There is an excellent article on TVTropes containing various examples of "Dwarves vs Elves" trope in literature and more.
One of the first examples of "Dwarves vs Elves" trope (or at least somewhat similar) in fiction can be found, quite suprisingly, in s-f book - it is H. G. Wells 1895 "The Time Machine". Although it doesn't feature dwarves and elves literally, it had two races:
- Morlocks - dark, ugly, living underground, with highly developed industry
- Eloi - childlike, tall, beautiful, living above ground
Of course, as in this trope, those two races don't like each other. More specifficaly, The Morlocks treat the Eloi as cattle.
Tolkien himself took this concept out of Norse mythology, with its written sources dating back to the 13th century. According to "Prose Edda" and "Poetic Edda", there are two contrasting types of elves:
- Ljósálfar ("Light Elves")
It was race of beatufil beings, described as "fairer than the sun to look at". They live in Vídbláin (or Alfheim), the third heaven, located above Andlang and Asgard.
Race of beings that living within the earth and with swarthy skin.
Since the Prose Edda describes the dökkálfar as being subterranean dwellers, they may be dwarves under another name, in the opinion of a number of scholars such as John Lindow .
There is mention in Norse mythology about race called svartálfar ("Black elves"). Scholars have commented that, as both attestations mentioning the beings and location appear to refer to dwarves, svartálfr and dwarf (and potentially also the dökkálfar) may simply be synonyms for the same concept.
 Lindow, John (2001). Norse Mythology: A Guide to the Gods, Heroes, Rituals, and Beliefs. Oxford University Press. ISBN 0-19-515382-0.