Good to see you are making progress with this project :)
For the second part, deleting the tiles if there are no enemies trapped in the completed section. After flood filling the area within a closed section, use a for each enemy loop and check the tile states at their position. If there are none overlapping the purple tiles then you can reset the purple and yellow tiles back to black.
You should be able to reverse engineer your code that handles the flood fill to determine if there is not a closed section.