I once heard that the sky is blue because it reflects the ocean and the ocean is blue because it reflects the sky. It's not a very satisfying answer. How would a system like that even start? Thankfully humans have the ability to reason and decades of science has culminated into an answer that is not only logical, but elegantly simple.
Understanding light as energy
Radiation is treated as a wave which has a frequency and wavelength. If you increase the wavelength, the frequency decreases, and if you decrease the wavelength, the frequency will increase. When we open our eyes, radiation floods in and our brain stitches together what we consider to be right now. This radiation is the visible spectrum, and it is not much different from the radiation that translates into music on your radio, or the microwaves that cook our food. The only thing that differentiates a microwave from visible light (or anything else on the electromagnetic spectrum) is the wavelength of the energy.
Within the visible spectrum, blues and purples are at the higher energy side (shorter wavelength) while oranges and reds make up the lower energies (longer wavelength). You can get an idea from the chart just how little of the spectrum we can see. In fact, most of what we know about the universe today is from observations made outside of visible light.
This is also how heat cameras work. Our body gives off infrared radiation, which is light with a wavelength slightly longer than what our eyes can see. These energy levels can differ, and the cameras are designed to translate this infrared radiation into a heatmap of the surrounding area in the exact same way that our eyes translate the visible spectrum into the colors we perceive.
Why the visible spectrum then?
Why is it the human eye is designed to see the visible spectrum? It seems too coincidental. Well, no. The star we orbit emits radiation of all different wavelengths, but its primary radiation is in the visible spectrum, with the highest amounts being the color green, the energy level right in the middle of the visible spectrum. Natural selection has preferred eyes that are sensitive to the main types of radiation that the sun puts out, because it has proved to useful for many creatures. Since a creature was more likely to see its predator, there was a greater chance it could react, not get eaten, and live long enough to pass the trait on to its offspring. Through billions of years, the eyeball has been fine-tuned to get the most use out of the star we circle around, and the genes to create such an eyeball have traveled down the line to us, the homo sapiens.
Skies of blue
Alright, back to the subject at hand. As was just mentioned, the sun emits radiation in the whole visible spectrum. When all of the visible spectrum radiation is overlapping, it appears white, which is what the Sun looks like if viewed from space. For us here at ground level though, the view is different. The air all around us (including miles above) is primarily full of oxygen (21%) and nitrogen (78%) molecules. All atoms are sensitive to certain energies of radiation, and as it turns out oxygen and nitrogen enjoy interacting heavily with wavelengths at the blue end of the spectrum while interacting weakly with wavelengths on the reddish end.
When white sunlight hits the atmosphere, the higher energy packets interact with the oxygen and nitrogen and get scattered in all different directions while the lower energies pass through unimpeded. It is this filtering of white light that gives us blue skies.
After you understand why the sky is blue, it almost becomes intuitive as to why the sunsets are comprised of yellows, oranges and reds. What is happening is when the sun begins to set, the light that we get to see from the sun has to pass through more of the atmosphere, which gives more time for the higher radiation levels to be scattered about. By the time the sunlight reaches the other horizon it has been greatly devoid of blues, purples and even greens. Because of this, only the warmer colors are making it through to our eyes, giving us majestic sunsets.
(This scattering of light is also responsible for the red tint of a lunar eclipse)