The machines were using solar power initially, but Morpheus points out that humans, knowing that the machines needed solar energy, "scorched the sky" presumably with nuclear weapons and thrusting the Earth into a nuclear winter-type scenario (this is what I assume. The exact line in the movie is:
We don't know who struck first, us or them. But we know it was us who
scorched the sky. At the time they were dependent on solar power and
it was believed they would not be able to survive without an energy
source as abundant as the sun.
Of course, as we know, the machines figured out that humans were a better source or energy.