The Internet tends to recommend the textbooks Genki I and II, although I have never used either. Other sources of note include imabi.net and Tae Kim’s guide , but the former is perhaps too verbose and the latter, in my experience, occasionally plays fast and loose with the grammatical definitions. I learned from a mix of both, and picked up a good deal of grammar from reading and listening. Specifically, finding anime, manga, or music that you enjoy and breaking down the sentences is an excellent way to internalize grammar and understand how it’s used in the wild. The important keyword for anime and manga is raw, meaning untranslated or un-subtitled. Both Japanese and English subtitles for most popular anime are available online , and watching anime with Japanese subtitles is useful at intermediate and higher levels.
I don’t have much else to say about studying grammar—just grind it out. We were all there once.