The answer to this can be divided into several categories that reflect the most basic trends in film music and its commercial use.
One category you can consider is when already existing popular songs are used in film. This practice is almost as old as talking films themselves. One of the best examples is Casablanca (1942), in which the song "As Time Goes By" runs like a leitmotif through the entire movie. Beginning in the 1960s, however, we see the practice of creating soundtracks that entirely consists of pop songs, rather than the classically-oriented background scores that had been standard before this period. The seminal film in this regard is The Graduate (1967), for which all of the songs on the soundtrack (excepting "Mrs. Robinson") had been recorded before production, meaning that they were not exclusively created for the film. However, there was a symbiotic (or reciprocal) relationship between the song and the film, in which the songs enhanced the popularity of the film, and the film did the same for the songs.
A second category to consider is the use of instrumental music written as background for a film which is then transformed into a popular song. The instrumental piece known as "Lara's Theme" from Doctor Zhivago (1965) was eventually given lyrics and become the song "Somewhere, My Love." The same was done with Nino Rota's music for Romeo and Juliet (1968), in which the principal recurring theme—primarily instrumental but sung to words at one point in the movie—was later given a new set of lyrics, was redubbed "A Time for Us," and eventually became immensely popular. Again, the subsequent popularity of those songs then fed the continued success of the films and, in the case of Doctor Zhivago, enhanced the nearly mythic status of the film.
A third category involves the use of pre-existing instrumental music or jazz which then takes on a new life and is marketed in muzak and other arrangements after its use in film. This is what happened to Scott Joplin's ragtime pieces in The Sting (1973), which were employed in the soundtrack to give a "period feel" to the film—despite the story being set in the 1930s, twenty years after Joplin's time. People who had never heard of Joplin or his music (or hadn't even seen the film) were then familiarized with "The Entertainer" and other rags in commercial arrangements.
The last category we'll mention is best exemplified in Nino Rota's music for The Godfather (1972). Rota's original music and his re-think of Italian and Sicilian folk songs were heavily marketed on records aimed at a mass audience; the mass appeal of these records even reached a large number of people who hadn't seen the film.
With the increasingly sophisticated marketing mechanisms in the digital age, all of these collaborative film and music marketing techniques have continued to be employed. Music that may have no inherent connection to a product is being used in advertising more than ever before. Just as music for films has become increasingly eclectic in source and style, the separate use of that music in other media is now more frequent and diversified than in the basic examples discussed here.