Take lessons.
The path to accuracy and speed on any instrument is the same formula. Years of methodical, slow, meticulous practice of basic exercises with a metronome. There are dozens of great books, DVDs, etc out there for developing technique. But they are all teaching the same basic thing. You need to get the movements in your muscle memory and optimize hand movement. One thing is to never play something faster than you able to. Messy playing does not fix itself through repetition. Repeating messy riffs trains your body to play messy.
My recommendation would be get your hands on a copy of Try Stetina's book Speed Mechanics for Lead Guitar. Again, there are many great ones out there but this one really goes into details that are missing in other books. There is also The Yng Way (a play on Yngwie Malmestin's name) but that really only covers his technique. And Intellishred by Kevin Dillard. Metal and shred sort of go together but the techniques apply to every style. All these books have countless exercises but Troy's book have descriptions of proper posture and suggestions for how to boost speed methodically and how to track your progress. Many of the other books just throw exercises at you and say play these faster and faster. imo Troy's book is a step above the rest in terms of education.