I started to type up an answer summarizing several theories about its origin and first use, but then I found that since the last time I tried to look it up, the Oxford English Dictionary has in fact added an entry for this term (in the online edition), along with some helpful citations. Turns out the phrase didn't originate with Hunter S. Thompson, or with Kubrick's Col. "Bat" Guano in Dr. Strangelove.
Here are the definitions provided by the OED, along with the earliest citation for each:
So, while batshit crazy certainly does seem to be influenced by the expression bats in the belfry as you suggest, its first meaning, in use by 1950, was simply a variant of bullshit. This use continued and overlapped with the "crazy" meaning: further citations are given for definition #1 from Dean Koontz's 1985 novel Door to December and from Seattle Weekly in 2002. Also, batshit as a standalone word meaning "crazy" appears to be older than the two-word phrase batshit crazy, at least as far as the written record shows.
There's anecdotal evidence scattered around the internet, like in this Straight Dope Message Board discussion, that definition #1 was in common use in the US military during the 1950s. Someone else points out there that Hunter S. Thompson may have picked up the term in the Air Force, from which he was discharged in 1958. Apparently he used the terms batshit, batshit crazy, and/or batshit insane in Fear and Loathing in Las Vegas and/or Fear and Loathing on the Campaign Trail '72, but I don't have either book handy to check, and none of the claims I've found includes a full quotation.