Not exactly photography but somewhat related due to picture editing.. What is the easiest color to see whether it's on black or white?
This isn't necessarily just of interest in photo editing — it can be useful in making strong color compositions as well. In general, yellow is the most visible and first-noticed color (random citation, but there are plenty of others) and yellow on black is widely regarded as providing the most visibile contrast. You'll often see it used for warning signs for this reason.
On a white, any dark color will do, and it's more a matter of whether you want to convey urgency (red) or calm and stability (green and blue), or go with the matter-of-factness of black.
Now, if you're looking for the color that works best to contrast with both black and white, something in the middle is logically most appropriate. Avoid yellow or purple, which are inherently bright and dark — see the great answer to my question for why Why are there no dark yellows, or bright violets?. Red, blue, or green would probably all work (and, generally, be more apparent than neutral gray.) Of course, if you're composing something where the color has semantic meaning, be aware of colorblindness, and make sure your selected hue is relatively high-contrast to those with differing vision.
Another option may be to outline your object, either in the object itself or through backlighting or rim lighting. That way, there's a line delineating your object as separate from the background.