They are autotrophs.
The process by which they get energy is called Photosynthesis - it is used by plants, algae and certain bacteria to harness energy from sunlight and turn it into chemical energy.