I think I would focus on the lean code and the EGR code. If the EGR is sticking open it will cause a rough idle. Typically your brake pedal will get really hard to push when this happens.
Chech for vacuum leaks especially around the intake and all the rubber vacuum hoses that are attached to the intake.