If a dragon gets spellhoarding templates and then takes class level in wizard do wizard levels and dragons hit dice stack or are they seperate? Also if they do stack then does the loredrake archetype stack with wizard as well?
They stack. For example, a young brass dragon has 10d12 dragon HD and the spellcasting of a 1st-level sorcerer; a spellhoarding young brass dragon has the same 10d12 dragon HD and the spellcasting of a 1st-level wizard. If the spellhoarding young brass dragon then takes a level of wizard, it will have 11 HD total (10d12 dragon + 1d4 wizard, so the first 10 have all-good saves, the last has good Will, etc.) and the spellcasting of a 2nd-level wizard.
A spellcasting class is an associated class for a creature that already has the ability to cast spells as a character of the class in question, since the monster’s levels in the spellcasting class stack with its innate spellcasting ability.