Thermostats on BMW can throw faults. BMW's are designed in such a way that your thermostat helps regulate your emissions output. If its engines a little hotter then usual due to your thermostat not opening correctly your Nox emissions will rise which will cause your car to fail, like it did. Only way around it is to replaced your thermostat, I believe they go for 115$ or so. Its a ridicilously easy job so if you want to do it yourself you just need a few tools.