Moderation is the best way to stop them. If you've got actual people going through posts and content and removing the low quality stuff, you'll maintain a much more well ordered and useful community than you would a mostly 'uncensored' platform.
Unfortunately, this has a few issues...
1. You need the manpower to actually check what's being posted on a regular basis. Or enough active members willing to help out that they'll do it for you on a voluntary basis as moderators. This is obviously easier for small sites like customer support forums and the average fan site.
2, You need to really, really limit bias as much as possible, so that you're booting out people or bots because of their behaviour rather than their political/social stances. This is what Twitter doesn't do at the moment, to the point being a 'progressive' troll is a good way to never get banned while being a conservative or having an unpopular opinion will get your account suspended for the smallest trangression.
3. A willingness to ban popular, rich or 'powerful' users as much as anyone else, if they break the rules. A good forum/community manager will just as easily kick out a troll with ten thousand posts as one with ten, but social media sites don't seem to have figured this out yet.
So for a community manager or site owner, moderation is the best way to stop internet trolls (and every other type of troublemaker or nuisance as well).
Making a user's post invisible to everyone but himself (shadowbanning or as vBulletin called it, Tachy goes to Coventry) and making their time on the site a nightmare due to fake errors (hell banning/miserable users) used to work. Note the word used to, since the internet is a lot more savvy about this sort of stuff and will usually figure out these systems pretty quickly now.
As for how to avoid internet trolls as a user? Well, stay off large social sites with few rules (or in some cases, extremely badly enforced ones) and go to places where the people tend to be a bit nicer to each other due to a shared interest or two. Less Twitter, more forums.
Stay fairly anonymous wherever possible. Seriously, trolls love knowing every detail about someone's offline existence and what annoys or upsets them. By giving less personal information, you force people to either REALLY dig for information to use or to attack your arguments rather than your background/appearance/personality.
Don't engage in arguments with trolls/idiots. The more you make it seem to affect you, the more pleasure a troll will get from their actions. If you've ever watched The Simpsons, you probably remember the scenes where Bart prank calls Moe's Tavern, right? Or how often, Moe would basically scream back down the phone in anger afterwards? That's what a troll wants to see. They want people who are easy to annoy.
So yeah. Moderated community platforms tend to be the best way to stop internet trolls, since they mean such users and comments are removed as quickly as possible.