c. 1200, "price, value," from Old French cost "cost, outlay, expenditure; hardship, trouble" (12c., Modern French coût), from Vulgar Latin *costare, from Latin constare, literally "to stand at" (or with), with a wide range of figurative senses including "to cost," from an assimilated form of com "with, together" (see co-) + stare "to stand," from PIE root *sta- "to stand, make or be firm."
The idiom is the same one used in Modern English when someone says something stands at X dollars to mean it "sells for X dollars." The meaning "equivalent price given for a thing or service rendered, outlay of money" is from c. 1300. Cost of living is from 1889. To count the cost "consider beforehand the probable consequences" is attested by 1800.
In phrases such as at all costs there may be an influence or echo of obsolete cost (n.) "manner, way, course of action," from Old English cyst "choice, election, thing chosen." Compare late Old English alre coste "in any way, at all."