Something like "turning lemons into lemonade"
There are some phrases of close meanings:


化干戈为玉帛   turn hostility into peace;
转危为安 / 化险为夷       turn danger into safety;
化压力为动力   turn the pressure of life into power;
转悲为喜 turn sorrow into joy;
化悲痛为力量   turn sadness into power;
变废为宝    turn rubbish into useful things;
化失败为教训  turn failure into lessons