We study the free objects in the variety of semigroups and variety of monoids generated by the monoid of all $n times n$ upper triangular matrices over a commutative semiring. We obtain explicit representations of these, as multiplicative subsemigroups of quiver algebras over polynomial semirings. In the $2 times 2$ case this also yields a representation as a subsemigroup of a semidirect product of commutative monoids. In particular, from the case where $n=2$ and the semiring is the tropical semifield, we obtain a representation of the free objects in the monoid and semigroup varieties generated by the bicyclic monoid (or equivalently, by the free monogenic inverse monoid), inside a semidirect product of a commutative monoid acting on a semilattice. We apply these representations to answer several questions, including that of when the given varieties are locally finite.