How to stop others from doing gheebat or any other forbidden thing in the best way possible? As this is also a matter of amr bil maroof wa nhi an munkir.

In regards to stopping another from gheebah, there is no one way to this because it depends on the other person's age, personality, relationship to you which will have an effect as to how you would address the situation. One who doesn't know what they're saying is gheebah, then you would tell them it's gheebah. If the other knows it's gheebah and justifies it, then you would have to address the situation in a different manner. People are different and ways to address situations with them would also have to be different depending on the person.
If one is doing gheebah, if you can remind them it's wrong to do gheebah and your telling them will have a positive effect, then do so otherwise busy yourself in other work or stand up and leave so you don't hear.

Amr bil maroof has conditions and one of them is that by advising another, if you know it will have a positive effect then you should advise otherwise there is no responsibility.

Below are all the conditions for amr bil maroof as per the ruling of Sayed Sistani

The following five conditions must exist in order for enjoining good and forbidding evil to be obligatory.

1. One must have knowledge of what is good and what is evil, albeit in a general sense. Therefore, enjoining good and forbidding evil is not obligatory on someone who does not know what good and evil are and does not distinguish between them. Indeed, in order to enjoin good and forbid evil, it is sometimes obligatory to learn and know what is good and what is evil.

2. One must deem it probable that it will have an effect on the wrongdoer. Therefore, if he knows that his speech and words are ineffective, the well-known (mashhūr) opinion among jurists (fuqahāʾ) is that he is under no duty and it is not obligatory on him to enjoin good and forbid evil. However, the obligatory precaution (al‐iḥtiyāṭ al‐wājib) is that he must express in any way possible his disapproval and displeasure with the wrongdoer’s improper actions, even if he knows that it will not have any effect on him.

3. The wrongdoer must intend to continue doing the improper and wrong actions. Therefore, in the event that the wrongdoer does not want to repeat his wrong actions, it is not obligatory to enjoin him to good and to forbid him from evil.

4. The wrongdoer must not be legally excused (maʿdhūr) in his improper and wrong actions; i.e. he must not believe that the improper act he did was not unlawful and that it was permissible (mubāḥ); nor must he believe that the good act he abandoned was not obligatory.

   However, if the evil deed is something that the Holy Legislator [Allah] is never pleased with – such as the killing of an innocent person – then it is obligatory to prevent it, even if the perpetrator is legally excused and even if he is not legally obliged to fulfil religious duties (mukallaf ).

5. The person enjoining good and forbidding evil must not be in danger of significant harm being inflicted to his person, reputation, or wealth. Furthermore, it must not cause excessive difficulty (mashaqqah) or unendurable hardship, except in the case where the good or evil act in question is regarded by the Holy Legislator [Allah] as being so important that one must endure harm and hardship in its cause.

          If the person who enjoins good and forbids evil is not in danger of any significant harm being inflicted on himself but other Muslims are – whether that be to their person, reputation, or wealth – then it does not become obligatory on him to enjoin good and forbid evil. In this situation, the level of harm must be compared with the act in question, and sometimes even when harm is caused, he will not be excused from enjoining good and forbidding evil.