When you want to create some nice vertical tabs via code you have to do:

<?php

$element = array(
  '#theme' => 'vertical_tabs',
  '#children' => $fieldsets,
);

$fieldsets can be a string of rendered fieldsets or an array with unrendered fieldsets. Here you can see how a structure of a fieldset form api can look like.