I would say that gospel music uses Christian/religious themes almost exclusively. Gospel music can have definite undertones of black soul music or white Southern gospel or country or blues or whatever, but the underlying theme is church-related or spiritual.
Soul music, on the other hand, can deal with either spiritual or secular themes. The music is coming from deep within the performer, but the subject matter could be a lost love, an unfaithful partner or the blues in general. Soul music is not limited to gospel themes, although the delivery can be equally as passionate as a gospel song.
The difference between R&B and Soul music is not as easy to define. Soul music definitely incorporated elements of R&B, but doesn't always follow the standard blues progressions of R&B or early rock and roll. A lot of the power of Soul music comes from the passionate interpretation of the lyrics by the lead singer, whereas many R&B songs succeed because of other elements, such as the guitar or harmonica breaks. A lot of blues bands can cover an R&B song like Howling Wolf's "Smokestack Lightning", but it takes a special vocal talent to cover certain Soul singers such as Etta James or Otis Redding.
Soul music in the 70s did blur the line between smooth R&B and Soul, however. I would say that much of the black music produced during that time would be best categorized as R&B, but certain performers such as Aretha Franklin, Marvin Gaye and Etta James continued in the Soul vein well into the 80s.