Can cacophony also be onomatopoeia?
Yes, it can.
It can be both but cacophony is slightly more specific as it's used for 'unpleasant' sounds such as noise ('bang' - something with a loud sound/volume).
Onomatopoeia is almost exactly the same and is defined as what a noise would sound like as a word ('shh' - so you hear the sound it makes).
Hope this clears things up!