So, in the game, only 10 years passed instead of 20. So that's part of it.
They mentioned the degradation of batteries when it comes to car batteries (and you see that Bill has separated cells stored in his garage refrigerator). The smaller batteries for flashlights?
Presumably someone's making them in a QZ.
With regards to the gasoline, Joel mentions the degradation of it to Ellie in their scene about siphoning gas. She asks why they have to refill every hour.
A lot of food is still plenty edible well past it's expiration date, just it degrades in quality and flavor. Acidic foods like Chef Boyaredee - yeah, it's not good to eat at this point (and certainly will taste a hell of a lot like the can it was stored in). A fully sealed can of a non-acidic food stored in a proper place could definitely be safe to eat after 20 years.