If you're prepared to do a bit of programming:
Download an extract of OpenStreetMap data for the UK, for example UK from [Geofabrik][1]. Save this to a database, for example by using the osm2pgsql tool to save it to a Postgres database with the PostGIS extension.
Download the [CodePoint Open][2] dataset from Ordnance Survey. This is free of charge and licensed liberally. Add this to another table in the same database.
You can then create a spatial query to associate OSM IDs (in one table) with postcodes (in another). The [PostGIS docs][3] explain the functions you can use in writing your SQL.
This is not for the beginner, but if you have some experience in SQL databases, you shouldn't find it impossible.
Note that CodePoint Open only has the centrepoint of each postcode area, not the full boundary; so this approach will sometimes suggest postcodes which are slightly 'off'. The only way to avoid this is to buy the expensive full data from Royal Mail or Ordnance Survey.
[1]: http://download.geofabrik.de/europe/british-isles.html
[2]: http://www.ordnancesurvey.co.uk/business-and-government/products/code-point-open.html
[3]: http://postgis.net/docs/manual-2.0/PostGIS_Special_Functions_Index.html