How many buildings or units can be stacked before they reduce their efficiency?

Trade Ports can stack linearly, each one giving the same bonus.

TEC and Vasari Orbital Refineries affect their planet and all planets within one jump. In an inhabitable system, the extractors can benefit from up to three refineries, while extractors in an uninhabitable system can benefit from up to four.

Advent Refineries are a bit different. After the Resource Focus research, you can toggle your Trade Ports into Orbital Refineries. This orbital refineries only benefit the planet they are located on, but stack additively. However, because of certain factors, you're usually better off leaving your Trade Ports as Trade Ports.

Broadcast Centers also stack linearly.

Shield Generators and Phase Jump Inhibitors do not stack.

Passive capital ship abilities do not stack.