Error code P0171 and P0174 on 1999 Ford Expedition

I have a 1999 Ford Expedition with 163,000 miles.
The vehicle registers a service code of P0171 and/or P0174, lean mixture.
The vehicle starts fine, but may stall or hesitate when first started or at red lights.
While driving, there is no issue.

I just replaced the MAF sensor and the EGR sensor, but no change in the condition.
In 2007 or 50K miles ago, the oxygen sensors were replaced.

What could be the problem or solution?

Thanks,

P0171 and P0174 means you have a lean condition

Vacuum leaks
Low fuel pressure
Exhaust leaks before the upstream oxygen sensors
Misfires of any kind (oxygen sensor reads unburned oxygen and PCM interprets a lean condition)

When were the plugs last replaced?
Have someone do a complete fuel pressure test
Listen for vacuum leaks at idle (any obvious hissing)
Have somebody use an evap/smoke machine to look for leaks

Fuel pump is a possibility, I think under warantee our 03 needed new plenum o rings. Might be time for a dealer analysis.

Assuming all the routine engine maintenace suggested in the owner’s manual is up to date. If not, do that first.

A fuel pressure test (at the rail) and a intake manifold vacuum test would tell you a lot I expect.

If this were my car, the first thing I’d do is a visual inspection of all the vacuum lines, then I 'd test each vacuum controlled device for vacuum leaks.