I assume by USB you mean a pendrive or external harddisk mounted to your file system.
You "detach" this by unmounting the device. For that you will have to use the umount command. You can use the device or the mountpoint, for example:
umount /dev/sdb1 or
See man umount for more details.
For shutting down your system, you use the
-h will "Halt or power off after shutdown". The manpage says:
/sbin/shutdown [-akrhPHfFnc] [-t sec] time [warning message]
So you can use it to shutdown your system after a specific amount of time. The following command will halt your system after 30 minutes:
shutdown -h 30
Now you have one command which should only executed after the other one was succesfull. This is done with &&, shorthand for a conditional statement and a feature of your shell (Note: || exists also). The second command will only be executed if the first one returned without any errors. This is indicated by a return code of 0. For example:
umount /dev/sdb1 && shutdown -h 15 will detach your USB and halt your system after 15 minutes.
If this doesn't answer your question, please be more specific.