I grew up with weevil outbreaks being common (father was a hoarder of food among other items) so once I got out on my own, I swore it would never happen to me again.
Well, it did in the early days because I also like stocking up on rice, flour and beans. Sigh.
And you may not know this, but all grain based food probably has bugs in it. Just in egg form and they can hatch when conditions are right. So you are always eating bugs in some form if you eat any crackers or pasta or the like. I just try to not think about it too often! ;)
So what I do now:
Anything that is beans, rice or grain-based (cake mix, crackers, pasta, etc) gets put into the freezer for a minimum of one full week. This is sufficient to kill anything that might be in egg stage in the food itself. So the only thing to worry about then is to not attract outside pests. This is mitigated by storing in glass or plastic airtight containers. I have mostly large jars, but some plastic bins that have good seals. We have a small chest freezer in our garage that we use for bulk meats and also where we put most of the beans/grains for their freezer time.
Baking supplies are always stored in the fridge. I devote one full drawer in my fridge to sugar, cornmeal, powdered sugar and the flour is on my back bottom shelf.
Rice and beans can live in the freezer forever if necessary, but I usually do end up putting them in jars in the pantry due to space.
Pantry is inspected once a month. I update a spreadsheet anyway so I know what I have and what I'm running low on and use that to menu plan and create shopping lists. So this is also my opportunity to inspect every thing. I take everything out and give it a once over before listing and putting it back. (okay, not can goods, but I do look at that shelf just to make an inventory). I wipe down the shelves with a solution of water/vinegar during this time as well.
So basically, just freeze stuff temporarily, move to airtight glass/heavy plastic after, and then inspect things before using and inspect the pantry on a regular basis. Should be simple and prevent any problems.