What you're asking is not automatic. There is no magic button that will remove the title and replace the background behind it. Any chance of doing so requires tracking skills, cloning skills, and a great deal of patience.
A more reasonable approach would be to find clean still frames from the open and try to stitch them together to make your own background.
It would also help if we knew which version of Star Trek you were trying to copy. There are a bunch of them. If you are trying to duplicate the original TV show then I would just build my own Starfield so that it closely matches the one in the open and then cut just as the Enterprise flies out of frame.
It's pretty easy to make a Starfield with just two layers with a bunch of white dots. You can generate the dots using noise and threshold if you want. Then you make the top layer 3D and slowly move it away from the camera to create the illusion of moving through the galaxy.
Oh, I know there isn't a magic button. I was expecting to have to put work into it. I just didn't know what tools to use to make it happen. And, like I said in the original post, I'm trying to do this with Star Trek: The Original Series's opening titles (with both the original version used in season one and the second version used in seasons two and three).
I would try to duplicate the Starfield and just cut between the shots. If I get some time tonight I'll show you how to make stars with noise and threshold. It's an old old trick but it comes from the same era as the original Star Trek.
As promised Dropbox - ST Titles.zip
I downloaded a copy of the Star Trek open, used Detail Preserving upscale to fit it to a D1 Square Pixel comp then nested that comp in Comp 1. I then picked the point where I would add my custom title and set some markers. I determined the speed of the moving star field by dragging out some guides and following one star on it's path then went about setting up my star fields by adding a solid and creating the non moving stars with Noise HLS, Box Blur, Threshold then Gaussian blur. I made a bigger solid and set up the moving star field using the nearly the same technique but with a few different settings. I then made the moving star field 3D and animated the Z position to get my stars to move at the right speed. Using the graph editor I determined that about 200 pixels per second was the right speed. The moving layer was set to the Add blend mode. I then put the star field pair on the bottom layer and used the original to set the in and out point and position of two 3D text layers. I then animated the opacity of the original footage to hide the old titles and expose my new background and titles. With a little tweaking I got the size of the star field and the density to match pretty close. You can spend more time if you like getting the match a little closer. The original moving star field background looks like it had 3 layers, two moving and one static. The technique I used is very close to the technique used to create early star field backgrounds digitally. They actually used Photoshop to create large stills and just animated scale so the look is very similar.
Have fun. This was fun for me. There are about a zillion ways to create a moving star field but this one quite closely matches the original look with not too much trouble.