Sounds like your car is switching into "limp home mode" and shutting the car off and then on resets the computer. There is a way to have the "air mass flow sensors" tested with BMW dealer testing equipment. Check your actuators that let air intake the engie, one or both might not be working and letting air into the engine. Next I would go to wiring plugs and check them. The engine does not have knock sensors so it could only be a few items. Last could be ECM problem.