How to combine usbdfu and usbtoserial code for ATMega8U2?

You can try burning just the DFU bootloader only, and then booting up the 8U2 in DFU mode. Then use the Atmel FLIP software to download the usbserial to the 8U2.