In-depth books? Tonal Harmony (with workbook, but don't use the chapter on binary form, my professors say it sucks pretty badly. I haven't bothered with it).
There has been an idea this century that you can reach good music by formula. It seems a roundabout and useless way to get there, to me. You're asking for a lot. Unless you're deaf, I'm assuming you have an idea of what sounds good to you and what doesn't. Play some melodies. If it sounds good, write it down. If it doesn't, heck with it. Add some accompaniments to your melodies. If you like them, write it down, if not, chuck it. You have an ear, and it can do a whole lot better than your calculator, I promise. I started writing music back in eighth grade. Yeah, it sounded like crap, and I'm sure I could revamp them after finishing basic music theory courses (up through post-tonal harmonies and binary form) at the undergrad level. But I think I wrote some pretty damn good stuff before going to college. The book I mentioned, though, will tell you what you want to know: why each note is there, what is it doing, and what are your other options. However, it will cost a pretty penny, but you might be able to get it used off amazon.
As for immediate things you can do for your current state: Learn all of your scales. Learn the I, ii, IV, V, and VI chords for each key, and their inversions. Finally, any good composer studies the works of other composers, so get some scores and start really looking at them to see what the composers do.