Please, don’t let this situation mess with your logical thinking just because of one confusing DTC description that isn’t helpful for diagnosing the problem.
Your computer isn’t throwing random codes. The P0171 code makes sense when you consider the real mechanical cause of the P0345 code, which isn’t just some electrical issue. If you can stick with me for another detailed explanation, I think it’ll help.
The fact that the P0171 (lean condition on Bank 1) took a while to show up is important. Look at how P0171 relates to the timing codes, especially since P0345 shows up at startup. If the cam is retarded, it opens the valves later, which means less air gets into the cylinder. This is a big clue, especially since the lean code is on Bank 1 and the timing code is on Bank 2. The lean condition on Bank 1 suggests that the timing on Bank 2 is off. The PCM adjusts the fuel injectors based on the air-fuel ratio, and a retarded cam on one bank leads to less air, requiring more fuel on the other bank. When the fuel trims go above certain limits, the PCM sets the lean code.
In my previous message, I listed four possible causes for your P0345: a bad phaser, a failed locking pin, a bent phaser finger, or the timing being off by a tooth or two. The appearance of the P0171 code makes it more likely that the timing is just off by a notch rather than being a startup issue. The rough idle could mean lower compression in several cylinders due to less air coming in.
Since you’ve done a lot of repairs, there might be other issues to check first. For the lean code, use your OBDII reader to monitor short-term fuel trim (STFT) on Bank 1. While idling, use an unlit propane torch to check for leaks around the intake manifold and injectors. If you find a leak, the fuel trims will drop quickly.
It would also be helpful to know any other codes you’ve seen, as they might give more clues.
Regarding the timing parts, did you use Ford OEM parts or cheaper aftermarket ones? There are good videos by FordTechMakuloco about checking for bent phaser fingers during installation.
If you determine the P0171 isn’t due to a vacuum leak, then you might need to remove the valve cover on Bank 2 to check for a bent finger, though I doubt that’s the issue given the lean code.
Unfortunately, you can’t confirm if the timing marks are off without a full teardown or professional equipment.
If you’re using Torque Pro, we might be able to gather some useful information, but it may not be definitive.
Good luck, and don’t replace the computer just yet!