You can set the task pane to hide during the OnSwitchView event, which occurs right before the first view is visible. There will be a short flash of it appearing and then disappearing (oh, well!), and then you can make it hide or show from code when the user clicks on the button, based on your needs.
Keep in mind though that the user can still open you task pane from the menus and keyboard shortcuts. So one solution for this is to set some simple message as visible in the task pane when you close it via code. Then if the user manually opens the task pane, they will see your message, and not an active task pane. The other option is to set all of the controls in the task pane to be disabled when you close the task pane via code... but this is more work.
Greg Collins [InfoPath MVP]