There is actually a whole discipline, which deals with such issues (among others), in one way or another: Astrobiology.
After reports of Streptococcus mitis on the Moon 1969/1970, the topic become more and more an issue of discussion. Today, there are sets of regulations on how a spacecraft, depending on its target, needs to be sterilized. This had led to the term Planetary Protection.
Methods for handling space probes basically include assembly in clean rooms and microbial reduction through heat and chemicals. In more detail, this means e.g. dry-heating, sterilizing wipes and aseptic integration. With heat being the safest method for sterilization, there are still problems with overheating electronics or scientific experiments. So further methods such as low-temperature, vapor-phase or hydrogen peroxide-based sterilization processes are under investigation.
The Committee on Space Research (COSPAR) has introduced a system of 5 categories for different types of exploration missions. For example, Category IV refers to landers on celestial bodies, which have the potential to host life and for which there is a possibility of contamination (e.g. Mars, Europa & Titan). Missions under this category are supposed to receive the best possible measures of sterilization.
For the second part of your question, Category V refers to sample-return missions to/from celestial bodies with a potential to support life. They are then referred to as "restricted Earth return missions". It is recommended that all returned equipment and samples shall be handled in accordance to biosafety level 4, which, although being a US regulation, is internationally accepted.