P0171 is a though one. What kind of mileage? Did you check your air filter? Sometimes rodents will build a nest in the airbox. Also could be a dirty MAF sensor, one of your HO²s starting to go out of specs. This code is really ballpark and doesn't point to a specific failure.
You've addressed the 2 most common cause for that lean code. Some people on here claim to have solved this code accidentally when they replaced their car battery. So even a failing or bad battery can cause this code to pop up. P0171 is more annoying than a mosquito near your ear. Do you have a good OBDII scanner? Sometimes if you look at misfire counts you may be able to figure out which cylinder is running lean if it's actually running lean and this may point you to a clogged injector. Did you try a fuel treatment?