How to create optgroups from taxonomy terms?
Is this what you are looking for:
http://drupal.org/node/76500#comment-2193734

I posted the code used in the comment.  All props go to Nate Anderson from drupal.org

&lt;?php
if (isset($form['taxonomy'][$vid])) {
  $tree = taxonomy_get_tree($vid);
  $parent = "";
  $options = array();
  foreach ($tree as $term) {
    if ($term-&gt;depth == 0) {
      $parent = $term-&gt;name;
    }
    else {
      if ($term-&gt;depth &gt; 1) {
        $options[$parent][$term-&gt;tid] = _modulename_spaces($term-&gt;depth, '-') . ' ' . $term-&gt;name;
      }
      else {
        $options[$parent][$term-&gt;tid] = $term-&gt;name;    
      }
    }
  }
  $form['taxonomy'][$vid]['#options'] = $options;
}

function _modulename_spaces($number, $char = ' ') {
  $output = '';
  for ($i = 0; $i &lt; $number; $i++) {
    $output .= $char;
  }

  return $output;
}
?&gt;