let x = fence distances perpendicular to the bldg
y = fence distance parallel to the bldg
xy = 12
cost, C = 10(2x+y) + 4x
using the area equation, solve for one of the variables in terms of the other (either x or y, your choice) , then substitute into the cost equation to get cost in terms of a single variable ... then do the calculus.