Do both these words mean "thank you"? If both mean thank you why are they spelled differently? Is one more formal than the other?
Both are different spellings of ありがとう, neither is more formal, although all three spellings may be differentiated by frequency (see below).
ありがとう "thank you" may be derived from ありがたい through sound change; ありがたい is a compound of 有る and 難い.
In forming compounds, the first verb conjugates to the ren'yōkei (= "masu-stem"). In compound verbs, like 有り得る or 押し付ける, this is usually all that happens, but for other compounds the okurigana (hiragana part of the verb) are sometimes omitted, so both 有難い and 有り難い are possible ways of writing the same word. (Here り is the okurigana of 有り.)
There are many other such examples:
- 受け付け = 受付け = 受付 "reception"
- 乗り物 = 乗物 "vehicle"
ありがとう is usually written in hiragana nowadays, but it may be written with kanji, like you suggest.
ありがたい 1987 (74%) 有難い 350 (13%) 有り難い 343 (13%) 有りがたい 17 ( 1%) ありがとう 7090 (93%) 有難う 420 ( 6%) 有り難う 102 ( 1%) 有りがとう 2 ( 0%) 受付 3916 (85%) 受け付け 633 (14%) 受付け 34 ( 1%) うけつけ 3 ( 0%) 受け付 1 ( 0%) 乗り物 470 (79%) 乗物 95 (16%) のりもの 16 ( 3%) 乗りもの 12 ( 2%)
As you can see, 有難う is about four times as common as 有り難う, but ありがとう is by far the most common.
Do both these words mean "thank you"?
Yes. (ありがとう,) 有難う and 有り難う are same.
If both mean thank you why are they spelled differently?
有り難う is correct way of writing, and 有難う is also correct. According to MEXT:
If there is no danger of misreading, excepting sentences' ending, you can leave out okurigana (Part of word written in Kana).
Is one more formal than the other?
I think 有り難う is formal.