This is a good question. All the answers so far gives you grammar references, but you need something like a pedagogical grammar course with exercises. I have no ready-made course, but the following suggestion might be helpful.
I used the Grimm Grammar by the university of Texas to get up to speed in German grammar. It has lots of articles about most aspects of German grammar. The articles are all pedagogical, unpretentious, with lots of examples and even some exercises. The problem is that they don't suggest any order for their lessons; if you follow it from top to bottom you will be an expert on German adjective declination before even having seen a German pronoun! But if you carefully choose which lessons you want to read this is a great resource.
The website Deutsch-lernen claims to have a free German grammar course, but it is nothing more than glorified declination tables. It might give you an idea of in which order you want to read the "Grimm grammar" though.
If you find a good way or some good resources to learn German grammar, remember that you are allowed to answer your own questions.