Grains (if not crushed) will keep for a year or more if kept cool (< 70F) and dry. I use a dehumidifier to keep the air in the basement fairly dry and this to keep the grain dry in the container.
If grains are crushed, they need to be used within a month or so.
Hops should be kept in the freezer, either in the pouches in which they were shipped or in a foodsaver bag to keep the O2 out of them. They last at least a year when stored like this.