What is this worm or larva I found in my walls
You are correct!, those are definitely mealworms. If you're not already aware, mealworms prefer to live in dark places (so under/in woodwork is expected) and typically eat decaying material, but are also partial to consuming new plant growth. 



During the larval stage of a mealworm (of which will eventually grow into a Darkling Beetle), a mealworm will undergo 10-15 molts before pupating. That being said, the collection of carapaces that are shown in your picture is probably the work of just a few beetles.

I cannot attest as to how long it takes for a mealworm carapace to deteriorate, but sure, those remains could very well have been there for decades. If the location in which you found these remains has a dirt floor, you could possibly try identifying trails that were left by the developed beetles. Their trails looks like this: