The Earth formed from a cloud of gas and dust about 4.5 billion years ago. The early Sun was much smaller and cooler than it is today, but it still emitted a significant amount of energy. This energy, primarily in the form of infrared radiation, heated up the Earth, which was a swirling mass of molten rock and gases at that time.
True sunlight, as we know it today, only became possible after the Earth had cooled enough for a solid crust to form and the atmosphere to develop. This process took billions of years, and it was during this time that the first life forms began to appear on Earth.
So, while the initial energy from the Sun was essential for the Earth's formation and the eventual development of life, it wasn't until much later that the Earth experienced the familiar light of the Sun that we see today.