5.7 hemi rough idle and low backfire out exhaust any ideas

well i have listened around all the manifold and vacuum and the injectors and dont hear any odd noises and i checked all the fuses and they are ok what confuses me is when this happens if i remove and replace both o2 sensors the backfire stops and the engine idles smoothly but it has happened before and im wondering why it would seem if there is a vacuum leak it would continue until the leak is stopped im kinda a rookie at this type of tuning so im learning as i go hopefully i can solve it.