P0171 - System to Lean (Bank 1)
What is the model year of your car? I'm assuming 2002.
For lean DTC, start first by looking for vacuum leaks. Even a tiny vacuum leak can cause issues.
Next exhaust leaks.
Clean the MAF. Use only a product designed for the job. It's cheap insurance. Not likely to solve your problem as the MAF is new.
Of course, the MAF could be bad. However, since you reported it ran better with the new MAF, somehow that seems like a long shot to me. IMO, seem more likely there is an additional issue.
A new PCV valve is also cheap and easy to replace. Remember that the PCV system is basically a controlled vacuum leak.
Research, inspect, and test. Throw parts at it only as a last resort.
A bad IAC is NOT going to cause a lean DTC.
The number one cause of bucking is an ignition issue. Followed by a air metering issue (vacuum leak or bad MAF).
Regarding the poor idle. Best to wait until the DTC's are gone. Quite possible that the issues causing the DTC is also causing the poor idle.
Have you done the tests called for in the other post?
Inspect the throttle body for worn parts, weak return spring, or general slop in the linkage.
>>
P0171
Air Measurement System
MAF sensor (contaminated, damaged, malfunctioning, etc.)
Fuel System
Fuel pressure regulator (leaking, malfunctioning, etc.).
Fuel filter plugged, dirty.
Fuel pump (weak, check valve leaking, etc.).
Leaking/contaminated fuel injectors.
Low fuel pressure or running out of fuel.
EVAP canister purge valve leaking (when canister is "clean").
Fuel supply line restricted.
Fuel rail pressure sensor (incorrect reading).
Air Induction System
Air leaks after the MAF.
Vacuum Leaks.
PCV system (leak, valve stuck open, etc.)
Improperly seated engine oil dipstick.
Exhaust System Exhaust leaks before or near the HO2Ss (exhaust manifold gasket, mating gaskets, etc.).
EGR System
EGR valve tube/gasket leak
EVR solenoid vacuum leak
Secondary Air Injection
Damaged/malfunctioning secondary air injection system (mechanically stuck valve).