There have been several posts on this problem with 645's. I would make sure you are using good gas and run a good gas treatment through it. Check your battery. If it is old it may be getting weak which will give you codes. Thermostat is a cheap part on most cars and typical not difficult, but I've never done it on a 645. I'm not sure how a thermostat would cause increased emissions, but maybe someone else can chime in on that.
'07 650i Coupe - Black Sapphire Metallic
M6 bumpers, skirts & wheels
BMW M Cross Spoke Composite 101 Rims 20"
HUD, Comfort Access