Energy from the sun is attained by plants through the process of photosynthesis. The process of photosynthesis is made available through the chloroplasts in plants. They use carbon dioxide, water, as well as the sun's energy.
The plants store this energy in the form of glucose, which can then be accessed by animals, the consumer. Animals access this energy using mitochondria, cellular energy factories.
Hope that helps, let me know if you want more details regarding the process or chemicals involved :)