Loose powder in sealed container in climate controlled area can last a long time. I've shot pyrodex that was over 10yrs old with no issues or loss of power.
Pellets, well that is different. If they are kept in a sealed container in climate control they will last longer. Just kept in those pyrodex boxes, its a crapshoot how long. I don't think there is a set time, too many variables. Some, like my buddy will claim they never go bad.
He swears that they don't go bad, and is still using pyro pellets that are quite old. No issues for him so far, but from what most folks say and what many report... he'll get bit eventually. I have never used pellets so I can't speak from experience on them.
One common theme I've seen, when someone claims they have lost powder or have some crazy erratic stuff is happening, its almost always with old pellets. When in doubt, get new. Or (much) better yet... get loose powder.