P0171: Excessively lean. Test for fuel contamination, dirty injector, or fuel pump not keeping up at high throttle.
P0172: Excessively rich. Fuel contamination, injector supplying too much fuel, saturated EVAP canister.
P0130: Open loop control condition for more then 12.5 seconds. Oxygen sensor problems.
Since the oxygen sensor is what tells the PCM whether the exhaust stream is too rich or lean, I'd say the root cause is O2 sensor-related. You have one in the exhaust manifold and another down below near the catalytic converter. Sorry, I don't have the experience to guess which one is more likely to be bad. I just have the shop manual and looked into the troubleshooting flowchart.
For more reading: http://en.wikipedia.org/wiki/Oxygen_sensor