The rising global demand for animal-based food has an increasingly detrimental ecological impact, exacerbated by significant food waste (approximately one-third of all food). This research aimed to analyze the possibility of changing the usually balanced feed with sustainable alternatives that remain as a by-product of the production of farms, grain processing, and breweries, thus promoting the sustainability of agriculture. The mealworm larvae were reared on different substrates: (1) agar-agar gels, wheat bran, and brewer’s yeast, (2) carrots, wheat bran, and brewer’s yeast, (3) sprouted potatoes, wheat bran, and brewer’s yeast, and (4) carrots, brewers’ spent grain and brewer’s yeast. For analysis, the frozen larvae were lyophilized and tested for chemical safety in three accredited laboratories. The results have shown that all tested samples had lower levels of pesticides than the detection limit. In scientific literature, we didn’t find studies on polycyclic aromatic hydrocarbons (PAH). In our study, we found PAH in the substrate and these toxins, as our study shows, can also enter the larvae, but no significant accumulation was observed (sum of benzo(a)pyrene, benz(a)anthracene, benzo(b)fluoranthene and chrysene was 0.0007 mg/kg). Furthermore, the total content of PAH, benzo(a)pyrene and histamine did not exceed recommended levels. We have noticed that the highest concentration of heavy metals (e.g., chromium—1.45 ± 0.02) was found in the sample with the brewer’s by-products. While numerous studies utilize plant-derived by-products, the accumulation of glycoalkaloids has not been explored. Among the all glycoalkaloids (tomatidin, tomatine, α-solanine, α-chaconine and solanidin), amounts of α-solanine and α-chaconine were the highest, detected in the sample with sprouted potatoes (175.12 ± 0.21 and 139.32 ± 0.32 mg/kg, respectively). The amount of total putrescine, tyramine, spermine, and spermidine in mealworm larvae was statistically higher compared to the amount detected in the substrate, and histamine level-on the contrary, was statistically significantly lower compared to the amount detected in the substrate. Considering the amount of toxic substances found in the substrate from the by-products, we can assume that mealworms did not accumulate high levels of toxins, which would violate regulations.