You may have an air leak: a modern car measures the air that comes into the system. An air leak past where it measures it is considered 'rogue air' and could cause the P0171 problem you're having.
Edit: make sure they indeed closed where the air filter goes in. Sometimes it isn't seated well. How familiar are you with things like the air filter, etc?
Edit2: is it still stalling after the car has been running for a bit? IOW, did they fix that issue and this P0171 issue is new?
Get some starter fluid or WD40. Start the car and spray it around certain areas. If you notice that the idle changes (likely ramping up a bit) just after you spray to then go back to normal, you found an air leak. The starter fluid, when sucked in, finds its way to the cylinder in effect giving it a bit of extra material to burn, causing the idle to briefly change.
Regarding where to spray, around rubber hoses that don't have clamps on them (those are usually vacuum lines) and that big plastic thing along the center of your engine (that's part of the air intake). Also spray it around your brake booster (that's the elongated larger round thing near your driver's side of the firewall, towards the top). No need to hose the area down, but just spritz it a bit.
Remember this stuff is flammable so use common sense. No open flames, lit cigarettes, etc unless you didn't really care for your eyebrows and facial hair anyways.
It could be a number of other things, but that^ is the low hanging fruit; something easy and cheap to try. It doesn't require any automotive knowledge so can be performed by anybody.
Once you find a leak, let us know and we'll talk you through fixing it.
Also find an independent Subaru shop. You really should not bring an 06 to the dealer. Instead, find a good mechanic that knows this car, establish a relationship with the shop. They'll take care of you way better than a dealer will.