how did you "flush" the system?. I advice you to do a reverse flushing with water and air pressure to the internal passage of the engine block.
connect flush gun adapter to the uper hose and let it flush to the lower hose.reverse flush the radiator too. A plugg system could cause the system to boilover the cap, if the rating of the cap is still good.
now, for the code p0171, the mass air flow sensor might be dirty or faulty.There could be a vacum leak downstream the MAF sensor.check your air filter for not been over oiled, that could cause the sensor to to be dirty.the MAF could be leaking silicone potting material used to protect the circuitry.
Mechanic On Wheels LLC