So I've been contending with a frequent P0171 "System Too Lean" check engine light and an occasional P0507 "Idle Air Control System RPM Higher Than Expected". My attempts to rectify included cleaning and later replacing the MAF sensor. Unfortunately both issues kept occurring and the car felt sluggish. Took the car in to Audi and they say the problem was simply a worn out rubber gasket on the oil dipstick tube. They replaced it for $35 out-the-door and amazingly the car seems to be fixed. It feels so much smoother and the CELs haven't come back [yet]. I hope the fix is permanent!

So...if you're experiencing the P0171 code and the P0507...it might simply be that rubber gasket!