These are old-fashioned and formal words. Centuries ago, blasphemy was against the law in many places in the English-speaking world, and "blasphemy" was the formal legal term for it. (In everyday English it would be called "cursing" or "swearing.")
Usually, blasphemy is speech, and sacrilege is action.
Suppose there were an imaginary city where people believed in a sacred deity named Zzzzz, and in the city there was a great Temple of Zzzzz containing a statue of Zzzzz.
If someone said "Zzzzz is not a real god," that would be blasphemy.
If someone broke into the Temple of Zzzzz and had a drunken party inside it, that would be sacrilege.
If someone said "I could spit on your Zzzzz," that would be blasphemy.
If someone actually spat on a statue of Zzzzz, that would be sacrilege.