P0171 is system too lean Bank 1
P0113 is Intake Air Temperature Circuit
So the system probably runs okay when you pull the pipe because it has that exhaust leak near oxygen sensor and thingks it is running lean when it is actually dumping in gas to compensate and is running rich. So, extra air leans it back out.
The intake air temperature sensor is bad and that could explain a lot too.
I am giving you a walk through diagnostic to help you. Just use the link below;
Sunday, November 25th, 2012 AT 2:20 PM