I've been browsing the Internet for reliable sources on how to do this and finally found something here.
Some guides tell you to clean your cupboard with bleach or even use insecticides, but I didn't really think using poison in a place where you keep food was a good idea and had some serious doubts about bleach. The Department of Entomology of Iowa State University states that it's not a good idea to use insecticides in an area where you store food and that "washing shelves with detergent, bleach, ammonia or disinfectants will not have any effect on insect pests". They recommend "freezing for 1 week or heating in a 140 degree oven for 15 minutes" and vacuuming your cupboard and getting rid of the vacuum bag which could turn into another colony of insects. Store everything inside airtight containers.
For more detailed information, you might browse here.
Bugs in food freak out a lot of people (and to be honest they freak me out a bit too), but try to look at the bright side. If bugs can survive in your flour, dried fruit or herbs, it means your flour/dried fruit/herbs are not so pesticide laden that no larvae could possibly survive.
I've seen more bugs inside flour and other food, than I ever have since moving to Spain and guess what? It was really easy to make sourdough starter with the flour here.