The myth says that the use of using X to mean “kiss” began in the Middle Ages, when most people were unable to read or write. Documents were often signed using an X. Kissing the X represented an oath to fulfill obligations specified in the document. The X and the kiss eventually became synonymous.
Sounds like a myth, but it’s true. Using a cross as a signature has been common since the Middle Ages. The X is the first letter of the Greek word for Christ and it was used as an abbreviation for that word–hence Xmas for Christmas. To kiss your mark indicated a sworn signature, like swearing an oath.
So why does O mean hugs? I couldn’t find a thing about that, but I believe O came much more recently as the logical accompaniment to X because of its association in “noughts and crosses” or Tic-tac-toe, the ancient game that uses Xs and Os.