Sounds like you are describing "piston slap" or "spark knock". Can lead to rough idle, poor fuel economy, the noise you are hearing, hesitation on acceleration, and loss of engine power.
Can happen on these engines, some are worse that others. Can be described as a dull pinging or metallic clunking sort of noise that is keyed to engine revolutions. Can be caused by a number of things. Since you have a 2000 Corolla - your 1ZZ-FE has VVT-i - that system can get stuck with the wrong valve overlap causing this piston slapping. Can also be caused by excessive clearances in the piston/piston walls. excessive carbon build up inside the combustion chambers, faulty injectors, oiling issues (oil consumption), vacuum leaks, induction system issues, faulty upstream O2 sensor, faulty MAF sensor, clogged cat, etc.
Need to diagnose this a little more - as it could be almost anything now. P0171 is likely the result of the issue - hearing a whistling sound at idle could be related - hard to start when warm is also possibly related. Covering the intake to "richen" up the mixture will not work with this engine or most modern engines - it will just adjust around the obstruction by varying the duty cycle to the injectors. Better to run a datalogging scanner to the car - see what codes are on the ECM, see if there are anything pending, and see if you can grab some data on the STFL and LTFL (short term fuel trim/long term fuel trim).
Might be worthwhile to pull the sparkplugs and see how they look like. If they are heavily worn or have excessive deposits on them - could be the cause of your issues. Definitely the least expensive check/replace at this point.
Quality of gas has a huge influence on how the car runs. Might try running a good quality fuel system cleaner + higher octane gasoline. The higher octane will resist pre-detonation, especially from excessive deposits inside the combustion chamber. If the sparkplugs are not the cause and the higher octane helps - could just be deposits inside the engine. That point - the amount of deposits and their composition will determine how to treat that issue. Basically, need to clean the induction system (intake manifold, throttle body) and inside the combustion chambers (valves, top of pistons, etc).
VVT-i issues are pretty common - the oil control valve (OCV) and the oil control valve filter can be easily clogged - causing valve timing/overlap issues. As this system is a variable valve timing system driven by an actuator and oil pressure - if the oil cannot get to where it needs to go, valve timing will be off. One check is to disconnect the OCV electrical connection and see if the engine stumbles or not. If it runs poorly, it is working correctly, if it doesn't seem to change - then you need to do some more diagnostics.
Vacuum leaks are very common and should be one of the first things you check. Check every vacuum line, hose union, hose tees, in around about the intake manifold, valve cover, and throttle body. Check the PCV valve and the associated hose. Check around the injectors for fuel leaks, check that the coil on plug igniters are in good condition/no cracks, check for exhaust leaks, check chassis ground points.
Battery been replaced recently? If this still has the original battery - could be time for a new one. A battery can be still strong enough to turn the engine over but not provide enough reserve battery power to feed all the electrical systems under certain conditions. Voltage fluctuations and electrical noise can cause the ECM to get confused - corrupt signals. Can cause all sorts of issues that can be hard to diagnose.