You can carefully try brushing the matts out, if they feel very close to the skin you should take the animal to a professional groomer. They may need to shaved off and if you not careful or not sure what you are doing you can tear the skin and that is painful to the animal.
If you've got a dog with enough hair to tangle into knots and matted sections, and they're difficult to remove without hurting the dog (or the skin underneath the hair), your best bet is to take it to a groomer (or your vet) and have them gently use the pet shavers. The blades are long enough to get under the knots and matts, and gently cut the hairs that are tangled. (I'm a former pet groomer, and this is the easiest way to get rid of those knots. If you attempt to comb or brush them out, it pulls on the dogs skin and irritates it badly. Don't wash and dry the dog beforehand, that will only make the tangled and knotted hair tighter).