Thermoelectric energy conversion offers a viable solution to harvesting waste heat and transforming it into usable electrical power. This investigation examines how oxygen and nitrogen heteroatom doping affect the structural and functional performance of anthracene-based molecular junctions. This work systematically investigates the influence of impurity type, location, and number. Findings reveal that oxygen incorporation, particularly when localized in the middle ring, or with increased impurity number in both middle and peripheral rings, substantially elevates thermoelectric performance, achieving a peak ZT of 3.5 in the D2O configuration. In contrast, nitrogen doping consistently reduced ZT values, irrespective of the impurity’s position or count.The results emphasize that accurately selecting the positioning of heteroatoms is essential for maximizing thermoelectric efficiency.