by default you cant do this as shutting the lid puts the macbook to sleep. you can use insomniax to prevent the macbook from sleeping when you shut the lid and it will continue to run.
but keeping the macbook running while the display is closed isnt a very good idea as there could be some heat issues if the cpu is under a fair load. just plug in the macbook, set the computer to never sleep and set the display to sleep after a few minutes in the energy saver prefs or if your using leopard set a hot corner to turn off the display.