In order to remain calm when among your friends, family and relatives, you should keep count of your acts on a daily basis, try to have a good temper, stay away from bad friends, take your social position into consideration and not intervene in issues that you are not responsible for. These things will help you overcome this problem. For more information, refer to the detailed answer.
Two issues have been pointed out in your question
1- Losing your temper and feeling insecure and vulnerable
2- Socializing with friends and family
These two issues are deeply related to each other, because having a bad temper causes you to lose your calmness, resulting in committing inappropriate actions (like making fun of others and annoying your friends). This does not mean that this is all your fault, but your conduct is a central factor to this issue.
Solving the issue of bad temper
To trace the reasons behind your bad temper is in need of deep and thorough psychological observation. At all events, you are suffering from this issue and you are aware of this problem. Being aware of the problem is the biggest step you take in the path of solving the problems. At this point, the key factor is to make all your effort to overcome your bad temper. We have a number of suggestions that will help you stay calm and patient amongst your friends and family.
A: A program of taking count of our actions: Imam Kadhim says: “One who does not take count of his deeds, is not from us; (He must do so in the manner that) if he has done a good deed, he should ask God to help him repeat it and if he has done a bad one, he should repent to God.“
You should have a notebook for this purpose. Write the number of times that you get mad in front of each day. Every night examine the behavior you had that day in a calm room when you are alone. If you had become mad for no reason, rebuke yourself and if you were successful, congratulate yourself. Carry out this program for one week and try to decrease the number each day. Continue for the second week and compare the results at the end of the week. Go on for a complete month until you slowly gain control over your anger.
B: Every night when you are going to sleep and you are lying in your bed, repeat these sentences: “I am capable of gaining control over my anger and to not lose my temper. God will help me in this path.”
C: Try to intermingle and socialize with people that have good tempers and always think of their conduct. Little by little, you will start to behave like them.
D: Some scholars (Ayatullah Bahjat) have advised to recite salawat with all faith to help overcome anger.
E: Taking up Islamic manners. The following are a number of these manners
1- One should like for others what he likes for himself and dislike for them what he dislikes for himself. Imam Ali says: “Like for others what you like for yourself and dislike for them what you dislike for yourself. And do not oppress, as you do not like to be oppressed. And expect from them what you would like them to expect from you.”
2- Answer people’s bad deeds with good and try to overlook their bad deeds as much as possible, instead of trying to get revenge, because great souls that have great capacity are always willing to forgive, while others try to get revenge.
Imam Ali says: “Quick forgiveness is the attribute of great men and quick revenge is the habit of the ignoble.”
He also says: “The manly are those who counter bad with good.”
3- Observe and understand your position and role amongst your family and friends. Only give your opinion when it is needed and refrain from doing so when you are not responsible of the issue that has been brought up. One can only intervene in different issues as much as his social position allows him. Neglecting this point can lead to the loss of credibility amongst people, enmity, grudges, friction between groups, many conflicts and many haram acts like gossiping, accusation, making fun of others and insulting them.
The Prophet once said: “One of the signs of a good Muslim is staying away from issues that are not related to him.”
Also, Imam Sadiq has stated: “Do not intervene in issues that have nothing to do with you, or else you will not be honored and respected.”
4- Creating and developing emotional bonds with the members of your family, relatives and your friends is another factor in helping develop a positive character. Approaching them with all kindness and having a good temper will encourage them to create friendships with you. Therefore, you should try to be as kind as you can with them. The Prophet stated: “One who says a kind speech to a believer to honor him will be showered with God’s mercy as long as the believer is happy.”
Also, Imam Baqir has stated: “Smiling at another believer is a hasanah (good deed).”
Therefore, you should try to create bonds with your close friends. To do this it is necessary to not only embrace Islamic manners, but also sincerely try to help them with their problem and guide and instruct them in fields in which they are in need of guidance. The least you can do is sympathize with them.
5- Within a society, you come across all types of people; good, bad, good tempered, knowledgeable, ignorant, rich and poor. We have no choice but to interact with them as we cannot live alone. However, in order to stay protected both from the worldly and spiritual aspect; one must refrain from befriending bad people. It is not appropriate for one to leave his pure and sincere friends for the corrupt ones.
Imam Ali says: “One who stays with the bad will not immune to their corruption.”
He also says: “It is good for the wise to be with the knowledgeable and good and to stay away from the sinners and the corrupt.” Therefore, try not to socialize with people that are used to sinning and making fun of others.
Sources for further reading:
1. The supplication of Makaarim al-Akhlaaq of Imam Sajjad (AS) and choosing an appropriate commentary that has been written for it
2. Noqtehaye Aghaaz dar Akhlaaqe Amali, Ayatullah Mahdavi Kani
3. Khodsaazi ya Tazkiyeye Nafs, Ibraahim Amini
4. The hadiths of the prophet (SAW) and the infallible imams (AS)
5. Akhlaaqe Mu’ashirat, Javad Mohaddesi
 Kulayni, Muhammad ibn Ya’qub, al-Kaafi, vol. 2, pg. 453, Daar al-Kutub al-Islaamiyyah, Tehran, 1986.
 His eminence’s official website, the section on mystical points.
 Harraani, Ibn Shu’bah, Tuhaf al-Uqul, farsi translation, Jafari, Behrdad, pg. 72, Islamiyyah Press, first edition, 2001.
 Tamimi Amidi, Abd al-Wahid ibn Muhammad, Ghurar al-Hikam, pg. 245, hadith 5005 and pg. 346, hadith 7953, Propagation Office Press, Qum, 1987.
 Ghurar al-Hikam, pg. 59, hadith 629.
 Muhaddith Nuri, Mustadrak al-Wasaa’il, vol. 9, pg. 34, Aal al-Bayt Institute, Qum, 1408 AH.
 Majlisi, Muhammad Baqir, Bihaar al-Anwaar, vol. 75, pg. 204, Al-Wafaa’ Institute, Beirut, Lebanon, 1404 AH.
 Shaykh Hurr Ameli, Wasaa’il al-Shi’ah, vol. 16, pg. 376, Aal al-Bayt Institute, Qum, 1409 AH.
 Al-Kaafi, vol., 2, pg. 188.
 Ghurar al-Hikam, pg. 431, hadith 9830.
 Ghurar al-Hikam, pg. 430, hadith 9796.