That's a very big question, and like a lot of very big questions, the answer ultimately comes down to "having an eye for that sort of thing". That's why even though the fundamentals aren't too terribly difficult to come to grips with, people like Amy Dresser are able to make a reasonably good living as assemblage artists in the world of commercial photography. Getting most of the way there, to the point of effectively selling the fake, can be done by mere mortals, though.
The first two things to worry about should be obvious, but I'll touch on them briefly anyway because I've seen a lot of work online that leads me to believe that the blindingly obvious isn't visible to everybody.
First, you need to be able to effectively mask your subject(s). There are, of course, at least two ways to mostly do that in-camera (with only a little help in post), roughly nine thousand ways to do it natively in Photoshop, and a few dozen plug-ins and other third-party tools to help with the procedure, but one still sees the Photoshop equivalent of cutting things out of a magazine with children's safety scissors from time to time. You didn't ask about masking, but for those reading who find that their main problem is that things look like cut-out paper dolls, there is plenty of online info about masking technique. (It doesn't matter what tools you're using, there will always be effort involved in doing it right.)
The second is having subject lighting that makes some sort of sense in the background's context. Note: it doesn't have to actually match. "Big production" lighting can work in just about any context, since it's obvious that your subject is being lit separately. You can create pockets of light in a dark forest or alleyway, provided that they make some kind of sense and you remember to put light where it would have fallen on the background in post. Fill flash on location is a thing; the eye will accept something that looks like that. That said, if you try to create "natural" lighting in studio, but the shadows are going one direction on your subject and the opposite direction on your background, it's going to be really hard to sell the fake. It's an awful lot easier to choose a different background image than to try to create a different lighting direction on your subject in post-processing.
Assuming you've gotten all of that right, most of the heavy lifting can be done with a few clipped adjustment layers and some analysis/visualizing layers to help you. I'll look at the analysis layers first; they'll help you to tackle one problem at a time.
Monochrome Viewing Layer
There are a lot of ways to do this in Photoshop. My preference is to use a Curves adjustment layer with the black point dragged all the way up to white and the layer set to Saturation blending mode, but there are other ways that are probably just as good. The idea here is to get rid of the distraction of colour altogether so that you can adjust the brightness and contrast of the subject to fit into a "working" black-and-white image.
Hue/Colour Viewing Layer
A solid-colour layer (whether a Solid Color "adjustment" layer or just a filled ordinary layer) at 50% grey and set to Luminosity blending mode will remove all of the tonal information in the image, leaving you with just the colour information. I'll admit that this way of looking at an image takes a little bit of getting used to; it's rather like a really badly-done paint-by-numbers sort of thing. Once you do get used to it, though, it can be a very effective way of helping you identify large-scale colour differences between your subject and background.
A Selective Colour adjustment layer. All of the colours — Red to Magenta — have the Black adjusted to 0% in Absolute mode, and all of the neutrals (White, Black, Grey) have the Black adjusted to 100% in Absolute mode. That will give you a weird-looking black-and-white image, where white represents 100% saturation and black represents 0% saturation.
Ordinarily, you'll be adjusting your subject to fit into the background rather than the other way around, but if you do need to adjust the background, it's more-or-less the same procedure, just with the adjustment layers, etc., either below the subject of clipped to the background/inserted foreground, as the case may be.
The first thing you want to do is to clip a Curves adjustment layer to your subject layer and turn on the monochrome viewing layer. (If you've never used clipping before, just put the Curves layer above the subject layer, right-click on the layer in the Layers panel, and select "Create clipping mask". Once that's done, the curve will only affect the subject layer.) Adjust the curve until the black-and-white picture looks just about right. With no colour to worry about, it's a lot easier to judge the result.
Once that's done, turn off the visibility of the monochrome viewing layer and turn on the hue/colour viewing layer. You can use either a Hue/Saturation adjustment layer or individual channels in a Curves or Levels adjustment layer (clipped to your subject layer, of course) to make the subject blend in better. Since that is a very odd way of looking at a picture, you're going to want to check it with the viewing layer turned off as well. With a bit of practice, though, you will be able to trust your eyes with the layer turned on. (If you are trying to match the look across two pictures/selections with similar content, using a layer of this type along with the colour histograms in the individual colour channels can speed this up a lot.)
Once that's done, turn off the colour viewing layer and turn on the saturation map. You can use any (or all) of Curves, Hue/Saturation, Selective Color or Vibrance adjustment layers to make the subject blend in to the background image. If individual colours need to be more or less saturated, you'll probably find it easier to use Curves, Selective Color or a targeted adjustment using a Hue/Saturation layer. (You'll need to turn off the visualizing layer to use a targeted adjustment; otherwise you'll just be selecting neutral.) There may be a very good reason why your subject should be more or less saturated than the background, though, so you will want to check the image with the saturation map turned off as well.
That's the "heavy lifting". What remains are things like colour spills from the environment on the subject. You may have created them when you took the picture, and there would probably have been some if you had shot the subject in the target environment. If there already spills in place, it's almost easier than without — you can just use a targeted Hue/Saturation adjustment layer to shift the hue of the existing spill to the desired spill. It's pretty much the same technique you'd use to eliminate blotchy redness from skin, and there are a whole bunch of tutorials on the web showing you how to do that. Lee Varis's video is as good as any. The only real difference is that you'd be selecting, say, the green spill from a chromakey background on the subject's hair and clothing instead of the blemishes on their face, and moving the hue and saturation of those areas to fit the environment. As with blemishes, you will need to mask the layer and paint in only those shifts you want, but if it's clipped to the subject layer, you never have to worry about spilling adjustments over into the background. If there are no identifiable spills, you'll have to put them there yourself if they're needed, and that's just tedious painting, perhaps using a luminosity mask to help you out.
Those are the basics, and it's definitely not a one-click solution even at the basic level. It will, though, get you to a fake you can easily sell. And it will get you to the point where going further, making an image that would only be suspected of being fake by experts (assuming no forensic examination is going on) if something utterly impossible is happening in the picture is just a matter of having some experience, a good eye, and a willingness to tweak the little details until no clues remain. You can do the heavy lifting in minutes; the full-blown "I can't believe it's not real" thing can take hours or days. And that's why people can make a living at it.