You get mold (and less visibly, bacteria) growth after 4-5 days because your water (humidity) content left in the deyhdrated food is greater than 5%. Typically dried apples (and other types of fiberous dried fruit) have humidity levels closer to 20% when you don't dry them to a crisp. That means the treats you make aren't shelf stable, but luckily this can be fixed with some experimentation.
Each food has it's own requirements for preservation. Here are some quick guidelines to try out on apples. For yams and bananas, I would try dehydrating them a bit more closer to being crisps.
Wash fruits thoroughly before dehydrating. I don't do this, but you could try using a "fruit wash" (product for washing fruit).
Dehydrating isn't sterilization - the dehydrator isn't hot enough to sterilize the food, so some of these 'nasties' are left on there and waiting for their chance to grow. Commercial-grade food is always sterilized. Because a dehydrater isn't sealed well, I suggest you nuke the treats in your oven for 5-10 minutes on high heat AFTER you dehydrate the stuff, experimenting to make sure you don't dry them out too much in the oven. Also, be careful because the sugar is concentrated in dehydrated fruit, so it will burn easily. Wrapping the fruit in tin-foil before placing it in your oven is a potential trick because this effectively sterilizes the fruit in a steam bath. If you use foil, you'll need to cook them longer - start with 15 minutes.
After the treats are dehydrated and sterilized, try storing them in air-tight containers and always away from light in a cool/dark place. They need 7-10 days to "equilize" the moisture between each dried piece of fruit. Make sure to shake the containers every once in a while so they don't all stick together.
BEYOND THIS, there are more advanced techniques that you can easily try - including conditioning the dried fruits and a number of fruit-baths that preserve the fruits with harmless chemical solutions, like Ascorbic Acid (vitamin C). Try reading more on this link from UC Davis:
(Start Reading on Page 7).