Have Toyota Questions? Ask a Mechanic for Answers ASAP
This code that you have P0171 means that the system is running to lean. About 99.9% of the time this usually means that the mass airflow sensor is contaminated. The mass airflow sensor is mounted with two screws on the side of the top portion of the intake air box lid. Remove those two screws disconnect electrical connector and down inside the extension housing you will see two tiny resistors that are probably dirty and contaminated if you spray them with carburetor/Choke cleaner or they even make mass airflow sensor cleaner you should be good to go ideally the sensor should be replaced this will get you by in a pinch. The only other possible option would be intake leaks along the intake manifold or the induction boot that goes to the throttle body. Check all your vacuum lines and so on. To clear the code remove the negative battery cable for about 10 minutes this will also reset the fuel trim values in the computer.
If you know that the mass airflow sensor is a known good part or you got it from Toyota and has not been contaminated or failed since you installed it the only other known problem we've had with this engine are the injectors. They are notorious to get restricted. Typically though you will get a couple of misfire codes along with the P0171 code you might want to try and clean the injectors with some good strong injector cleaner and recheck the mass airflow sensor. If you have not done so please do not forget to rate my assistance at three or higher. After you remove the negative battery cable to reset the long and short fuel trim make sure the field from does not start to rise above five or 10% positive if it does then you still have an issue with running lean.