You can't use such a literal-minded interpretation in the real world. The real world is complex and fuzzy.
For instance, in species with sexual differentiation, two males or two females cannot mate, but are considered the same species.
For a more precise definition, you would have to, say, look at the probability that a pair of organisms of the appropriate sex from two different populations would be able to mate, and produce viable offspring (that is, offspring that could themselves mate and produce more offspring).
Asking about a single organism that happens to be infertile, or a single pair that happens not to be able to mate or produce viable offspring, is not particularly interesting, but at a population level you could use a statistical test to get a probability distribution, rather than a yes or no answer.
See https://en.wikipedia.org/wiki/Species#Difficulty_defining_or... for more information.
Note also that it can be the case that two different species can mate, and produce offspring, but the offspring itself is not viable (cannot mate and produce offspring). This happens in the case of mating two closely related species, such as when mating a horse and donkey to get a mule (https://en.wikipedia.org/wiki/Mule), or a lion and a tiger to get a liger (https://en.wikipedia.org/wiki/Liger).