pretty sure it's an expensive issue. you'll need new head. it's a problem with the head design, oil won't recirculate, etc. I may get some terms off, but i was at my mechanic's today to discuss the clunking noise (see other thread here!) and he talked just about one N52 engine in his shop that had same issues, plus warning codes thrown up and motor needed new head. it's bad, and bmw receommends this, there is a SIB on it even. I'm dreading this issue myself but mechanic said it's actually very rarely he sees this though heard of it numerous times. That was his first car, 325i E92.
In europe the cost was 3k euro to fix, so ... 4k USD give or take.
I hope it's not the same in your case of course and it's something less serious.
but my mechanic says symptoms were exactly like yours and engine doesn't basically work properly and stalls at times. New oil helps a bit, and some vanos component replacement helps temporarily but the problem is with the cover itself, it won't recirculate oil properly. There are english terms for this, but I'm translating so sorry if it's unclear, i can always go retrace the words from real oem if interested. New part is modified and fixes the problem btw.
'07 TiAg E86 Z4 Coupe 3.0si