2001 Z3 2.5/Misfire
Though your prob could have multiple explanations, it sounds like it is in the fuel management system. Highly doubt ECU unless it is a common concern for your vehicle. I own a 1.9 Z3 and it would abruptly stall in mid stream (usually during acceleration in 2nd or 3rd. I went to Auto zone for free plug in diagnostics. It was a camshaft position sensor. I picked up BMW part, replaced it, and it runs great again. OBD (on board diagnostics) check will shorten your research tremendously. Use a parts store for diag.