I have asked this question to many Rabbanim, and still have not been able to get a reasonable answer, so I thought I would try asking it here, and see what people thought.
It says in Devarim 4;2:
לֹא תֹסִפוּ עַל הַדָּבָר אֲשֶׁר אָנֹכִי מְצַוֶּה אֶתְכֶם וְלֹא תִגְרְעוּ מִמֶּנּוּ לִשְׁמֹר אֶת מִצְוֹת יְ־הֹוָ־ה אֱלֹהֵיכֶם אֲשֶׁר אָנֹכִי מְצַוֶּה אֶתְכֶם
Translated:
Do not add to the word which I command you, nor diminish from it, to observe the commandments of the Lord your God which I command you.
At this point, I am usually given the answer: "Purim and Channuka ar mitzvot derrabannun (from the rabbis) and since they don't claim that it is a mitzva deorita (a mitzva directly from torah) they were allowed to astablish it".
Now the problem I have with this statement, is that I have a second source.
There is a Gemara in brachot that says (and I'm paraphraysing) that if you quote your rabbi on something that he never said, you get karres (being cut off from G-d).
Now I quote the actual bracha that is said on Channuka (it's pretty much the same for Purim, but I couldn't find a text to copy, and I don't know how to type manually in Hebrew)
ברוך אתה ה' א‑לוהינו מלך העולם, אשר קדשנו במצותיו וצונו להדליק נר של חנוכה.
Translation:
"Blessed are You, Lord, our G-d, King of the universe, Who has sanctified us with His commandments and commanded us to kindle the Hanukkah lights.
Now according to the bracha, it is saying that G-d himself commanded us to light the channuka candles, which is in fact not true, as the torah was given far before the story of Channuka.
Around this time, I usually get the answer: "It says in the torah that you have to listen to the rabbis, therefor, since the torah says listen to the rabbis, and the rabbis say light candles on Channuka, than the torah is saying light candles on Channuka".
Now I have a huge problem with this, because they could have very easily worded the bracha such that it said "Blessed are You, Lord, our G-d, King of the universe, Who has sanctified us with His commandments and commanded us to follow the ways of the rabbis, who have told us to kindle the Hanukkah lights."
Now I go back to the gemara that I quoted earlier. If you get karres for misquoting your rabbi, thank Kal Vachomer wouldn't you get karres for misquoting G-d himself???
So how were the rabbanim able to create Channukah and Purim in the way they did? It seems like they directly violated the laws of the torah.