If you have both the P0171 and P0174, it could be a massive vacuum leak. Check the worm clamps where you took out the hoses to do the TH fix. Also try spraying carb cleaner to suspected areas (gaskets, joints, etc). If the idle changes, you found your leak.
Also clean the MAF sensor.
MAF sensor cleaning
http://www.contour.org/mods/mods.php?s=howto&displayid=36
and
http://www.contour.org/ubbthreads/showflat.php?Cat=&Board=zetecmaint&Number=989728&page=&view=&sb=5&o=&fpart=1&vc=1
and
http://www.autozone.com/servlet/UiBroker?ForwardPage=/az/cds/en_us/0900823d/80/1b/cb/25/0900823d801bcb25.jsp
Per TSB,
P0171 - System Too Lean (Bank 1) The Adaptive Fuel Strategy continuously monitors fuel delivery hardware. The code is set when the adaptive fuel tables reach a rich calibrated limit.
Fuel System:
�· Contaminated fuel injectors
�· Low fuel pressure or running out of fuel (fuel pump, filter, fuel supply line restrictions)
�· Vapor recovery system (VMV)
Induction System:
�· MAF contamination
�· Air leaks between the MAF and throttle body
�· Vacuum leaks
�· PCV system concern
�· Improperly seated engine oil dipstick
EGR System:
�· Leaking gasket
�· Stuck EGR valve
�· Leaking diaphragm or EVR
Base Engine:
�· Exhaust leaks before or near the HO2S
�· Secondary air concern
Powertrain Control System:
�· PCM concern
P0174 - System Too Lean (Bank 2) Same as DTC P0171, but Bank 2. See Possible Causes for DTC P0171