Is it safe to use drywall anchors for a heavy bookshelf between two studs?
Yes this will be fine if you use the right type of anchor, you need toggle bolts of some sort.  For example a 3/16" toggle bolt in 1/2" drywall can support 70# of load.  If you have two or three of these on the middle shelf bracket, it will be more than adequate.  

I'd recommend snaptoggles, eztoggles, or other variant that holds the toggle in the wall without the bolt - these are much easier to use.  



When you select your shelf brackets, you'll want something that you screw fast to the wall; you don't want something with the "keyhole" type mounting holes, where you basically hang the shelf brackets off the screws.