Get the code read again to be sure it's the same one. AutoZone will do it for free - except in California.
P0171 is a lean code. O2 or air leak is most likely the problem.
Before you spend money on the O2, double check the accordian tube on the intake tract as those can crack and not be easily detectable, then check the vac lines under the hood - particularly the hard plastic 3/4" corrugated ones near the fire wall. I had to pull mine & replace them with some regular vac or fuel line tubing. Easy job.
Good luck.