Communication is the biggest key to any relationship, and roommates are no different.
Open up the channels of communication early: Talk frankly about how excited you are, if you are nervous, etc. Get it out; they probably feel the same way. Doing so will establish that you're both committed to making it work, even when the honeymoon is over.
Look at yourself and your own habits, think of what a roommate would most likely complain about and point blank say "Look, if my [snoring, late nights, music, etc] become a problem tell me". In selecting a roommate you want to make sure that your lifestyles won't conflict.
Setup a flat message board, such as a fridge whiteboard or notepad in kitchen area. Some things, though, are better to talk about in person. Don't say, "Clean the bathroom"; say "Give me a call when you get a chance". Nobody likes to be told what to do or be "talked at", think about things from their shoes, even if you may be mad at them.
Speaking of getting mad ... avoid waiting until your roommate steps on your toes before saying something. When you sense a situation could occur talk to them ahead of time. Don't stew about things, get it out, chances are he/she will appreciate you talking to them instead of moping around. A little effort and maturity is a worthwhile investment, it will go a long way towards helping you enjoy your place. Sometimes you will have to be the bigger man, so to say.
Handling disagreements in a functional way is difficult. Like any relationship, it will have its ups and downs. How things go when it's "down" determines how happy you are.
Remember, you're unhappy (to put it mildly), and your goal is to become happy again. This will involve some charm and charisma on your part. Being the one to initiate things is usually the best way to accomplish this: It puts you in control, demonstrates your willingness to work things out, and takes the burden off of them somewhat.
Think through a given situation before you approach your roommate, run through the conversation in your head. What are you going to say? What are they going to say back? And so forth.
Remember, it will take both of you to make things work, part of that requires you to understand your roommate's position. The other is to effectively communicate yours, and persuade them into seeing it. Unless you're living with a complete jerk, your roommate will be willing to work with you once he understands where you are coming from. Using the understanding of his position to illuminate yours will let you talk as non-combatively as possible.
Some things cannot be lined with roses, though. If you have to be blunt, say so. Add that you're not trying to be unreasonable, but you feel strongly, and want to work things out.
Nothing is gained if you "suck it up" or by backing down when its time to talk. The same can be said of going on a rant and yelling at them. The key is to get your point across without putting them on the defensive. Once someone is in a defensive mood any rational conversation is impossible. Table a discussion for an hour if things get heated up, but don't let them drag out over days. That's days of unresolved misery for you.
Avoid heat of passion "discussions" by bringing up problems before they come to a boiling point. Again, talk to your roommate. Telling your friends for weeks about how they have been annoying you will eventually culminate with you loosing your cool. The longer you put off talking to the other person the longer you're unhappy.
Nobody likes to be mad, and good discussions often come easier than you'd think, with just a little effort to approach them and share your feelings.
Chances are you probably have a cell phone, but if you don't, consider getting one. Pagers are also nearly as handy and cost a lot less if you're on a tight budget. This will give your roommate (and friends) a way to get hold of you any time, and at least give you a message. Most severe roommate problems arise from one person "broad siding" another; be it with a house unexpectedly full of people or "borrowing food" without asking.
A common contention; sometimes its not your roommate that can drive you crazy, it's his or her obnoxious friends. Think about that before moving in with someone, you'll be in the company of their friends as well as themselves. Are you OK with them being around with you not there?
Frustrations easily mount when you or your roommate come home to a bunch of guests unexpectedly. Unless you're both social butterflies 24x7, agree to talk to the other person by cell phone/pager before you give the go ahead for your "crew" to swing by for some brews and watch the game. Again, in deciding on a roommate this is another point to check and make sure your lifestyles don't conflict. You're looking for someone with whom most of the time will not have a problem with people coming over when you want. When one of you wants to keep it quiet one night, it won't be a big deal.
Bedroom locations are a major key to enjoying your living area. If your bedroom isn't a place you feel comfortable, you're going to be unhappy and prone to having problems with your roommate. Check a prospective place out before agreeing to share it. Online floor plans greatly help with this.
Wall sharing with common areas, other apartment units, and other bedrooms are the biggest things to think about. For example, if your roommate says he likes to play PlayStation 2 until 3am and you like to hit the sack at midnight, avoid sharing a wall with the TV. Usually you won't have much flexibility in floor plans, and you'll have to choose between sharing a wall with a common area, or another bedroom. Weight things out: If you're a night owl, sharing a wall with the TV area might be the way to go.
Doorways and bathrooms are another thing to remember. Your roommate will be coming in and out of these while you're trying to sleep, do they need to travel by your door? Sharing a wall with the bathroom may look good, but at 6am when the noisy shower wakes you up your feelings may change. Check things out, run the shower, see how loud it is (you should check out the water pressure anyway!). Remember things will be quieter once your things are there, too, but don't count on it.
Like to sleep in? A window that lets sunlight at the crack of dawn may be something to avoid. Also, nearby roads can wake you up, especially in the winter plowing season. Think about distance and sheltering from the street, as well as parking.