Did you search "P0171" on this forum? There is a ton of troubleshooting info archived here.
In a nutshell. P0171 indicates that the engine ECU "thinks" cylinder bank #1
(passenger side) is running lean, and P0174 indicates that the engine ECU thinks cylinder bank #2
is running lean.
You don't know yet if there is actually a lean condition, or if the ECU is getting bad data from the various sensors that control fuel/air ratio. The surging, hunting, and (reported) lean mixture are frequently signs of an air leak into the intake system.
So, search the forum for "P0171" for tech details and tales of other people's experiences, and:
1. How many miles are on your odometer?
2. When was the last time the MAF sensor was cleaned?
3. When was the last time the air-fuel and oxygen sensors were replaced?
4. Have you checked for any air leaks into the intake tract on the engine side of the throttle body? Loose intake manifold bolts? Loose throttle body bolts? Disconnected PCV valve hose?
5. If more than 150K miles, has the fuel pump ever been replaced?
6. Etc, etc.