Fascinating piece of folk etymology from Spenser (Shepherds Calendar, June).
But the sooth is, that when all Italy was distraicte into the Factions of the Guelfes and the Gibelins, being two famous houses in Florence, the name began through their great mischiefes and many outrages, to be so odious or rather dreadfull in the peoples eares, that if theyr children at any time were frowarde and wanton, they would say to them that the Guelfe or the Gibeline came. Which words nowe from them (as many thinge els) be come into our vsage, and for Guelfes and Gibelines, we say Elfes and Goblins
It’s a nice fit but of course completely untrue. Here are the true origins from OED.
Elf: Old English ælf strong masculine = Old High German alp (Middle High German, modern German alp nightmare, Old Norse álfr (Danish alf) elf < Old Germanic *alƀo-z; a parallel type *alƀi-z (compare Swedish elf, Danish elv) appears in late West Saxon *ylf (found in plural ylfe < *ięlfe) = Mercian, Kentish *ęlf, Northumbrian *ǣlf, one or other of which is represented in the modern word. (The modern German elf is believed to be adopted < English; Middle High German had elbe a female elf.)
Goblin: Apparently < Old French gobelin (late 12th cent. in an isolated attestation; subsequently in Middle French (a1506 as gobellin ); French gobelin ), apparently ultimately < ancient Greek κόβαλος rogue, knave, κόβαλοι (plural) mischievous sprites invoked by rogues, probably via an unattested post-classical Latin form; the suffix is probably either Old French -in or its etymon classical Latin -īnus -ine suffix1. Compare later (apparently < Greek) post-classical Latin cobalus, covalus, kind of demon (16th cent.).