Long before the Elves awoke, Yavanna created the Two Trees of Valinor to give light to realm of the Valar. So began a reign of peace in Valinor, but Middle-earth was lit by starlight alone, and Melkor worked in the depths of Utumno in the north of the World. We are not told how long this time lasted, just that 'the ages drew on'; this period would have lasted roughly 10,500 years. It was during this period that Aulë made the Dwarves, and set them to sleep until the coming of the Elves.
When Oromë discovered that the Elves had awoken at Cuiviénen, great changes came about. The Valar made war on Melkor to protect the Elder Children of Ilúvatar; Utumno was destroyed and Melkor brought in chains to Valinor. The Valar also summoned the Elves to dwell in their land, and many answered this summons.
A period of three ages (about 2,900 years) followed. Melkor was imprisoned in the halls of Mandos, and the Valar and Eldar dwelt together in the light of the Trees. In the darkness of Middle-earth, the Dark Elves who had not journeyed to Valinor still dwelt, and the Fathers of the Dwarves stirred. Men would not appear until some time after the end of the Years of the Trees.
These Years came to an end when Manwë released Melkor from his imprisonment. For a time, the Dark Lord pretended friendship with the Eldar, but he turned back to the darkness. With Ungoliant, he destroyed the Trees, stole the Silmarils and fled back to the north of Middle-earth. Seeking revenge, Fëanor led a great part of the Noldor out of Valinor and back to Beleriand.
So the Years of the Trees came to an end. At this time, the Valar made the Sun and Moon to give light to the World, and the Years of the Sun began, and with them the First Age.
Tolkien provides precisely dated annals for the Years of the Trees, provided in the Annals of Aman (in Morgoth's Ring, volume 10 of The History of Middle-earth). According to this source, the Trees shone for a total of 1,495 'Valian Years'. Valian years are rather longer than solar years - one Valian Year is equivalent to about 9.582 Years of the Sun, so the Years of the Trees lasted in the region of 14,325 years, in our terms. All estimates of duration in this entry are based on figures from the Annals of Aman.