Old English to "in the direction of, for the purpose of, furthermore," from West Germanic *to (cf. Old Saxon and Old Frisian to, Dutch too, Old High German zuo, German zu "to"), from PIE pronomial base *do- "to, toward, upward" (cf. Latin donec "as long as," Old Church Slavonic do "as far as, to," Greek suffix -de "to, toward," Old Irish do, Lithuanian da-).
In Old English, the preposition (go to town) leveled with the adverb (the door slammed to) except where the adverb retained its stress (tired and hungry too); there it came to be written with -oo (see too).
The nearly universal use of to with infinitives (to sleep, to dream, etc.) arose in Middle English out of the Old English dative use of to, and it helped drive out the Old English inflectional endings (though in this use to itself is a mere sign, without meaning).
Commonly used as a prefix in Middle English (to-hear "listen to," etc.), but few of these survive (to-do, together, and time references such as today, tonight, tomorrow -- Chaucer also has to-yeere). To and fro "side to side" is attested from mid-14c. Phrase what's it to you "how does that concern you?" goes back a long way: