see the bad idle is caused normally by a bad egr...
when the egr gets dirty, the valve starts to stick open, and at idle its normally closed...so with it open, extra air is getting into the engine after the MAF sensor..so the ecu does not know about this air, and it causes a bad idle