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.
'98 Blue E36 320i - SOLD '06
'06 Silver E90 320d - SOLD '10
'07 Blue E90 325i - SOLD '12
'07 Silver E86 Z4 Coupe 3.0si - SOLD '16