Thank you for the comments. This problem is confusing me because it seems just the idle is affected, so this should lead to the idle control valve. However, since it gets much better after unplugging the MAF, then it can also be the MAF. I haven't considered the EGR valve, but after reading the comments maybe I should. Can the EGR be cleaned with electronic cleaner spray? How about the intake manifold gasket? I've read another post where this is suggested as the cause of bad idle/stalling.

Thanks again.