The idea behind optical soundtracks is beautifully simple. The white line running down the dark strip varies in width. A lamp shines through one side of the strip and hits a photodetector on the other side. The photodetector's output runs through an amplifier and drives a speaker. The vibrations of the sound are translated into changes in the white strip's width. The photodetector sees and variations in light intensity and reproduces the sound (see this page for details). The optical sound system is easy to add to the film and reliable over the life of the film.
This same optical system was used in theaters playing 35 mm films when talking movies were first released. In the 1950s optical soundtracks were replaced by magnetic recording -- magnetic strips just like those on a cassette tape were applied to the film and sound was recorded on them (see How Cassette Tape Works for details). Magnetic recording allowed for stereo sound and surround sound, and also improved the sound quality. But there were problems with magnetic strip life. Also, the magnetic strips made the films a lot more expensive.
In the 1970s, stereo sound using two optical tracks was made possible by Dolby. This system allows for stereo playback and surround sound, and offered Dolby noise reduction as well. Dolby has been improving the system for many years -- see the links for details.
Here are several interesting links: