Kronecker-type identities and formulas for sums of squares and sums of triangular numbers