2001 2.3l will be a Duratec 2.3l, just FYI, so not related to the earlier Ranger 2.3l Lima engines.
p0171 means O2 sensor closest to exhaust manifold(upstream) is reading too much Oxygen in the exhaust.
This can be confusing unless you remember that, an O2 sensor can read Oxygen content only, it can't tell a drop of gas from a drop of spit, lol, so lean as far as O2 sensor is concerned means too much air NOT necessarily to little fuel.
When you have a misfire code as well then that can cause the p0171 code.
When air(oxygen) and fuel are put into a cylinder and ignited most of the oxygen is consumed as it burns with the fuel................, if that air and fuel fails to ignite(a misfire) then all that air(oxygen) is pumped out into the exhaust manifold and the O2 sensor sees that as too much oxygen in the exhaust, so computer adds more fuel because there was an incomplete burn, as far as it knows, when it reaches a pre-set limit of adding fuel it will let you know by setting p0171 code, i.e. it is adding more fuel but Oxygen level isn't dropping.
I would first address p0301, misfire on cylinder #1, pull the spark plug(s) on #1 make sure gaps are correct and spark plug tip looks good, slight brown coloring, not black or shiny white.
I would then disconnect coils for a no start and crank engine, remove spark plug again and look at its tip, it should be wet with fuel, if not them fuel injector may be dirty or clogged.
I hate the idea of "shooting the Messenger" but..........upstream O2 sensors usually last 100k miles, and they can give computer wrong reading, this will usually show a specific O2 sensor code but not always.
Downstream O2 sensors last longer since they see cleaner exhaust.
These are both the same kind of sensor so swapping them around can tell you if upstream senor itself was the problem.
EDIT:
I see the picture now, that is the A/C compressor, yes it will cycle on and off even if A/C is off, it is used to dry the air in the cab to prevent windows from fogging up.
Air is blown past the cold evaporator(A/C) in the cab, this causes moisture to collect on it, drys the air, then in the winter this cold dry air is run past heater core to heat it up, it is then blown on the windshield, defrost, where the dry warm air absorbs the moisture on the cold glass to defog it.
Same principle as moisture collecting on a cold glass of beer on a warm day, air near the glass cools down and can't hold the moisture so leaves it on the cold glass surface.