Both "to" and "of" here are prepositions. From the OED, the usage of "of" in the first sentence is in the sense,
X. Expressing possession and being possessed.
In particular, definition 35. a:
Belonging to a person or thing, as something that he, she, or it has or possesses.
1954 D. Abse Ash on Young Man's Sleeve 65 He buckled the bumper of the car.
Note that here, the lyrics of the song is largely interchangeable with the song's lyrics. The idea is that the song is taken as a whole unit, and the lyrics are a constituent element.
Correspondingly, the usage of "to" in the second sentence is in the sense,
V. Indicating addition, attachment, accompaniment, appurtenance, possession.
In particular, definition 15. b:
To the accompaniment of; as an accompaniment to; also indicating the tune to which words are set;
1906 H. Belloc Hills & Sea 116 The two trumpets of the battery sounding the call which is known among French gunners as ‘the eighty hunters’, because the words to it are ‘Quatre-vingt, quatre-vingt‥chasseurs’.