Is it possible to use dishwashing soap as an alternative insecticide? How would that and what are the components of the dishwashing soap that would kill the insect?
I'm not completely confident that the aforementioned post is a duplicate, because the question explicitly asks "Why do cockroaches burst from soapy water?" While this question explicitly asks "Can soap kill cockroaches and/or ants?"
The short answer to your question is yes.
According to this website:
The soapy water kills [cockroaches] by forming a thin film over the roach's breathing pores that stays in place due to surface tension, causing the roach to suffocate.
Ants are killed in a similar manner (see this archived Reddit post).
For a more scientific read, check out this paper: Behavioral Responses and Mortality in German Cockroaches (Blattodea: Blattellidae) After Exposure to Dishwashing Liquid.