Having just gone through the P0171 code with my old Geo tracker, this code is usually due to a vacuum leak somewhere. Check the hoses and especially the EGR valve diaphragm and the charcoal canister. Even a small leak will set this code. Another cause is a bad O2 sensor.