Could be the Crankcase ventilation valve that is failing.
I have an E39 with the same M54 engine that was having problems with cold starts, sometimes it would need 2 or 3 tries and when it worked i had rough idling but after it warmed up it was good for the whole day until next morning . . . the same thing happened every morning cold start. Replaced it and now cars works perfectly.