Get it good and wet, put in a LOT of conditioner, and then comb it VERY carefully - with a good wide-tooth comb, NOT with a brush. Start combing at the ends of the hairs (pick up the tail, and start combing, say, the last inch of the tail). Be gentle and use a LOT of patience. When you get the last inch combed out, then start combing a half-inch above that, and so on. Work your way up the tail that way. It won't do any good to start above a knot and try to comb down - that just makes the knot get even bigger and tighter.
With the mane, you might want to consider just roaching it - manes are shorter, so they grow out a lot faster than a tail does...also, they're not as critical to the horse's insect control as the tail is.