My 171/174 woes have been intermittent for the past year. I ended up just learning to deal with staring at the CEL.
FWIW, I have no vac leaks and MAF cleansing never helps. Considered the o2 sensors but just never got around to it. In a sense, it's really not a big deal to me since I only drive it on Sundays, heh.
Well, it's been on for the passed few months straight and things are normal as ever. I gassed up yesterday and I recall when I was putting the gas cap back on, I had some difficulty just cause I simply wasn't lining the threads up well. Well, once on, I gave it the super duper annoyingly amount of turns and clicks. Just for good measure cause I felt like an idiot trying to get it back on. 
Once back inside and ready to roll, I turned the key and imagine that.... the CEL was gone. I never made it home last night to check to see if a leaky or loose cap could cause a 171/174, but it went all last night without coming back on. Anyone know if a cap issue can cause these or if it throws a different code altogether?
Gary Noonan
'01 S/C VX / '18 Forester XT