P0171 means your fuel system has adapted all the way to its lean clip, which is usually about 20% lean, and it still can't bring the fuel-air mixture back to normal. There are separate tests for the HEGO (P013* series), doesn't sound like that's your problem. If you're running lean, mileage won't be affected, if anything it will get better, but at the expense of a hotter exhaust.
Try the trick of spraying cold start spray (what you used to spray in carburetors on cold mornings) around the gaskets and hoses in the engine to see if you get a rpm spike. That will show you where your leak is.