To do this, you would use something like the following:
echo JRoute::_('index.php?option=com_mycomponent&view=categories&catid=20&Itemid=50');
Joomla will automatically turn this into a SEF URL using the JRoute()
class.
For more information on supporting SEF URL's with your component, have a read of this:
http://docs.joomla.org/Supporting_SEF_URLs_in_your_component
Hope this helps