Hi, first do the easy things...
check vacuum lines first (replace those bent and cracked), that is easy and cheap and can make a lot of difference, especially when idling.
Then check sparkplug connectors (check that they are not cracked) and plugs.
And then the fuel filter, if it is clogged your engine could be short on fuel which causes the shut off.
Also don't forget to check that every sensor is correctly attached to its wires (my dad's '87 325e auto had a suddendly stalling engine and was a sensor that sometimes de-attached)
Then some more complicated or time consuming stuff..
Clean the throttle body, remove carbon deposits but beware with those chemical solvents that could eat the plastic parts and sensor fixtures. Also don't dettach the throttle position sensor unless you know how to adjust it.
Clean and inspect the distributor rotor arm (my dad's car suffered from a general lack of power and sudden shutoffs from a worn one)
Make sure the two fuel pumps (the one at the fuel tank and the one under the car) are working properly)
If you know the settings and have some means to measure them, check the sensor readings (throttle position and airflow meter specifically)
Hope some of that fixes it.