What length toggle bolt to use?
One does not use toggle bolts in studs. They're for hollow-wall applications and would require you to drill very large hole through the stud flange, which isn't a great idea. 

It's also fairly difficult to drill the cabinet for toggle bolts, transfer the locations to the wall, drill larger holes for the togglers, insert the togglers in the cabinet, then get all the togglers into their respective holes in the wall. It's a real hullabaloo and a thing to be avoided. 

Use three or four screws with sheet-metal (fine) threads in each of the available studs and you'll be fine. Since most of the pull-out force is at the top of the cabinet, you might use two screws near the top. 

To answer your actual question, though, toggle bolts should usually be just long enough that, when the wings are folded back and the bolt is inserted, they can open up behind the wallboard. Whether they can be longer depends on clearance, of course.