Bads utility function
The branch of microeconomics that you seem to be looking for is the study of externalities—activities that have side-effects that (positively or negatively) effect the welfare of others. The Wikipedia article on the topic is here.

Any good introductory/undergraduate level textbook will have a treatment of this topic. For example, Hal Varian's "Intermediate Microeconomics: A Modern Approach" (which would be my recommended first port of call) has a chapter on externalities. A slightly more specialised treatment can be found in a textbook on so-called public economics such as "Intermediate Public Economics" by Myles and Hindriks.

These books also contain examples of how goods with externalities can be formally modeled.

Alternatively, because externalities are a standard element of the economics curriculum, a Google search for "Externalities lecture notes" will turn up lots of freely-accessable PDFs that give a good overview.