They use CO2 (and/or bicarbonate) for carbon, light for energy and nitrogen-containing ions (nitrate, nitrite and ammonia/ammonium) to build their proteins, just like plants do. Some marine tank hobbyists use "algae scrubbers" to remove nitrates from the water.