A P0171 is indicating a fuel trim malfunction, specifically that the fuel mixture is too lean.
What this means is that the computer is reading the exhaust, it is:
1- seeing too little fuel content in the exhaust
2- it has attempted to add fuel to balance the mixture out
3- after adding maximum amount of addition fuel, the system is still too lean
There are a few reasons this can happen. While the knee jerk reaction is you can have a fuel pressure problem preventing proper fuel delivery, this is not always the case (and fairly rare until you get into pretty old vehicles). It is more often either a result of a vacuum leak in the engine, particularly if there has been recent work done, where a failed gasket or hose is sucking additional air in that is not metered, leaning the mixture out.... or a sensor related issue (MAF reading incorrectly, Oxygen sensor stuck).
What you would want to have done is get the vehicle hooked up to a live data scan tool so that the fuel trims can be watched while the engine idles. Then use brake cleaner or (unlit) propane around the engine to see if there is a leak. If there is a vacuum leak then when you get near it the engine will draw in the additional "fuel" and cause the idle to change as well as the fuel trims will start to go negative (rich).
If there are no vacuum leaks externally, then we would look at the oxygen sensor reading (front sensor) and see if it is alternating properly. It should be switching voltage about once every second. If it is stuck at a voltage and does not move even when you blip the throttle, the sensor is failed.
If the oxygen sensor is reading properly, then we would want to read the MAF value to make sure it is within range.
Beyond those items you get into long shot scenarios.... weak fuel pressure (so check fuel pressure), timing has jumped (valves opening too soon, bring in too much air) etc.
More often than not it will end up being a vacuum leak or sensor failure though.